feat(exn_bt): in show/pp, do print the backtrace when present

This commit is contained in:
Simon Cruanes 2025-04-15 10:10:02 -04:00
parent 3a5eaaa44d
commit 2b00a0cea1
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -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