From 2b00a0cea141fab54dd15e52bba34fea2ab832ac Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 15 Apr 2025 10:10:02 -0400 Subject: [PATCH] feat(exn_bt): in show/pp, do print the backtrace when present --- src/core/exn_bt.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/exn_bt.ml b/src/core/exn_bt.ml index cfed6421..4931b96f 100644 --- a/src/core/exn_bt.ml +++ b/src/core/exn_bt.ml @@ -3,7 +3,15 @@ type t = exn * Printexc.raw_backtrace let[@inline] make exn bt : t = exn, bt let[@inline] exn (e, _) = e let[@inline] bt (_, bt) = bt -let show self = Printexc.to_string (exn self) + +let show self = + let bt = Printexc.raw_backtrace_to_string (bt self) in + let exn = Printexc.to_string (exn self) in + if bt = "" then + exn + else + Printf.sprintf "%s\n%s" exn bt + let pp out self = Format.pp_print_string out (show self) let[@inline] raise (e, bt) = Printexc.raise_with_backtrace e bt