Use IO.catch in async

This commit is contained in:
Christoph M. Wintersteiger 2024-07-31 16:57:03 +01:00
parent 8123e95a5f
commit 262e57e7c2
No known key found for this signature in database
GPG key ID: 50B5FDA31455CFF3

View file

@ -76,10 +76,14 @@ module Make (IO : IO) = struct
end
let async (self : #base_server) f : unit IO.t =
self#spawn_query_handler
(fun () -> try f () with err ->
Log.err (fun k -> k "LSP async notification handler failed: %s" (Printexc.to_string err));
IO.return ());
self#spawn_query_handler (fun () ->
IO.catch f (fun exn bt ->
let msg =
spf "LSP async notification handler failed with %s\n%s"
(Printexc.to_string exn)
(Printexc.raw_backtrace_to_string bt)
in
IO.return @@ Log.err (fun k -> k "%s" msg)));
IO.return ()
(** A wrapper to more easily reply to notifications *)