Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Monitor.exn_to_error #5

Open
wants to merge 1 commit into
base: tracing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/monitor.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ let send_exn t ?backtrace exn =
loop t
;;

let exn_to_error exn =
match exn with
| Error_ {exn; backtrace; _} ->
let backtrace =
match backtrace with
| Some backtrace -> `This (Backtrace.to_string backtrace)
| None -> `Get
in
Error.tag ~tag:"monitor.ml.Error"
(Error.of_exn ~backtrace exn)
| exn ->
Error.of_exn ~backtrace:`Get exn
;;

module Exported_for_scheduler = struct
let within_context context f =
Scheduler.(with_execution_context (t ())) context ~f:(fun () ->
Expand Down
6 changes: 6 additions & 0 deletions src/monitor.mli
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ val get_next_error : t -> exn Deferred.t
backtrace from the error (see discussion in [try_with]). *)
val extract_exn : exn -> exn

(** [exn_to_error] extracts the exn from an error exn that comes from a monitor,
repackaging it into an [Error.t]. If it is not supplied such an error exn, the
backtrace is inferred and the exn is packaged as given.
*)
val exn_to_error : exn -> Error.t

(** [has_seen_error t] returns true iff the monitor has ever seen an error. *)
val has_seen_error : t -> bool

Expand Down