From bb520d90b5782a2ad109a6c2e492882842aa07bd Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 22 Dec 2023 21:38:31 -0500 Subject: [PATCH] ppx: make sure to reconstruct backtraces --- README.md | 8 ++++---- ppx_trace.opam | 2 +- src/ppx/ppx_trace.ml | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 986f770..7f89707 100644 --- a/README.md +++ b/README.md @@ -100,11 +100,11 @@ let f x y z = do_sth y; begin let _trace_span = Trace_core.enter_span ~__FILE__ ~__LINE__ "sub-span" in - try - let _res = do_sth z in + match do_sth z with + | res -> Trace_core.exit_span _trace_span; - _res - with e -> + res + | exception e -> Trace_core.exit_span _trace_span raise e end; diff --git a/ppx_trace.opam b/ppx_trace.opam index 14992f3..b00d78c 100644 --- a/ppx_trace.opam +++ b/ppx_trace.opam @@ -9,7 +9,7 @@ tags: ["trace" "tracing" "observability" "profiling" "ppx"] homepage: "https://github.com/c-cube/ocaml-trace" bug-reports: "https://github.com/c-cube/ocaml-trace/issues" depends: [ - "ocaml" {>= "4.08"} + "ocaml" {>= "4.12"} "ppxlib" "trace" {= version} "trace-tef" {= version & with-test} diff --git a/src/ppx/ppx_trace.ml b/src/ppx/ppx_trace.ml index e088cf9..8f59221 100644 --- a/src/ppx/ppx_trace.ml +++ b/src/ppx/ppx_trace.ml @@ -52,13 +52,14 @@ let expand_top_let ~ctxt rec_flag (vbs : _ list) = let _trace_span = Trace_core.enter_span ~__FILE__ ~__LINE__ __FUNCTION__ in - try - let _trace_ppx_res = [%e e] in + match [%e e] with + | res -> Trace_core.exit_span _trace_span; - __trace_ppx_res - with exn -> + res + | exception exn -> + let bt = Printexc.get_raw_backtrace () in Trace_core.exit_span _trace_span; - raise exn] + Printexc.raise_with_backtrace exn bt] in let tr_vb (vb : value_binding) : value_binding =