Skip to content

Instantly share code, notes, and snippets.

@emchristiansen
Created January 14, 2022 01:34
Show Gist options
  • Save emchristiansen/b5e1ad709c353a0253eca86182c89268 to your computer and use it in GitHub Desktop.
Save emchristiansen/b5e1ad709c353a0253eca86182c89268 to your computer and use it in GitHub Desktop.
Unable to get stack traces when using Lwt.catch
let bar () : unit Lwt.t =
assert false ;
Lwt.return_unit
let foo () : unit Lwt.t = bar ()
let run () : unit Lwt.t = foo ()
let run_catch () : unit Lwt.t =
Lwt.catch run (fun exn ->
Format.printf
"@{<error>@{<title>Error@}@}@. @[<h 0>%a@]@."
Format.pp_print_text
(Printexc.to_string exn) ;
Lwt.return_unit)
let () =
print_endline "Start" ;
(* This version doesn't print a stack trace. *)
Lwt_main.run (run_catch ())
(* This version does print a stack trace. *)
(* Lwt_main.run (run ()) *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment