aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEmilio Jesus Gallego Arias2020-02-11 11:33:55 +0100
committerEmilio Jesus Gallego Arias2020-05-15 02:19:01 +0200
commit7e078b070b3acf6c0b24d66a150b09a7df57b09d (patch)
tree380d22bee9648f4b828141f035500d9d2cd3ad04 /lib
parent56e23844e80e6d607ad5fa56dfeedcd70e97ee70 (diff)
[misc] Better preserve backtraces in several modules
Re-raising inside exception handlers must be done with care in order to preserve backtraces; even if newer OCaml versions do a better job in automatically spilling `%reraise` in places that matter, there is no guarantee for that to happen. I've done a best-effort pass of places that were re-raising incorrectly, hopefully I got the logic right. There is the special case of `Nametab.error_global_not_found` which is raised many times in response to a `Not_found` error; IMHO this error should be converted to something more specific, however the scope of that change would be huge as to do easily...
Diffstat (limited to 'lib')
-rw-r--r--lib/cErrors.ml11
-rw-r--r--lib/cErrors.mli4
2 files changed, 10 insertions, 5 deletions
diff --git a/lib/cErrors.ml b/lib/cErrors.ml
index 62d465c703..cb64e36755 100644
--- a/lib/cErrors.ml
+++ b/lib/cErrors.ml
@@ -25,12 +25,17 @@ let _ =
in
Printexc.register_printer pr
-let anomaly ?loc ?label pp =
- Loc.raise ?loc (Anomaly (label, pp))
+let anomaly ?loc ?info ?label pp =
+ let info = Option.default Exninfo.null info in
+ let info = Option.cata (Loc.add_loc info) info loc in
+ Exninfo.iraise (Anomaly (label, pp), info)
exception UserError of string option * Pp.t (* User errors *)
-let user_err ?loc ?hdr strm = Loc.raise ?loc (UserError (hdr, strm))
+let user_err ?loc ?info ?hdr strm =
+ let info = Option.default Exninfo.null info in
+ let info = Option.cata (Loc.add_loc info) info loc in
+ Exninfo.iraise (UserError (hdr, strm), info)
exception Timeout
diff --git a/lib/cErrors.mli b/lib/cErrors.mli
index 21d41c996d..cf1857cf04 100644
--- a/lib/cErrors.mli
+++ b/lib/cErrors.mli
@@ -21,7 +21,7 @@ val push : exn -> Exninfo.iexn
[Anomaly] is used for system errors and [UserError] for the
user's ones. *)
-val anomaly : ?loc:Loc.t -> ?label:string -> Pp.t -> 'a
+val anomaly : ?loc:Loc.t -> ?info:Exninfo.info -> ?label:string -> Pp.t -> 'a
(** Raise an anomaly, with an optional location and an optional
label identifying the anomaly. *)
@@ -34,7 +34,7 @@ exception UserError of string option * Pp.t
(** Main error signaling exception. It carries a header plus a pretty printing
doc *)
-val user_err : ?loc:Loc.t -> ?hdr:string -> Pp.t -> 'a
+val user_err : ?loc:Loc.t -> ?info:Exninfo.info -> ?hdr:string -> Pp.t -> 'a
(** Main error raising primitive. [user_err ?loc ?hdr pp] signals an
error [pp] with optional header and location [hdr] [loc] *)