Closed sapristi closed 4 years ago
Ok it turns out I was just using Printexc
the wrong way.
Using the following middleware gives the right backtrace:
let handle_exc =
let filter : (Opium_kernel.Request.t, Opium_kernel.Response.t)
Opium_kernel__Rock.Filter.simple = fun handler req ->
(
let handler' = fun req ->
try%lwt
Lwt.bind (Lwt.return req) handler
with
| _ as e ->
let backtrace = (Printexc.get_backtrace ()) in
let backtrace_msg = Printf.sprintf "An error happened while treating the request:\n%s\n%s"
backtrace
(Printexc.to_string e)
in
(`String backtrace_msg) |> respond'
in
handler' req
)
in
Rock.Middleware.create ~name:"handle_exc" ~filter
Hello, I have issues to get backtraces from a middleware.
Here's a full example:
Whichever the route, i get the following backtrace:
(the exception name below that is the right one, no problem here).
You will notice one route is raising an exception from the
ocaml-re
module, while the other is raising directly withfailwith
. This is because in my usecase I noticed that the backtrace was the right one when I usedfailwith
in my code, but was the same one as given here when an exception was raised byocaml-re
.Now I don't manage to reproduce a working backtrace, neither in my usecase, nor in the given example, so I don't really know what to make of all this...
Do you have any clues as to what could be going wrong here ?
Context
The code is compiled with the following dune file:
dune is version
2.7.1
, opium is version0.18.0
, and ocaml is4.08.1