From 6bf93e2c5e1fed452a0b79fbc453c434a8bebece Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 25 Nov 2024 15:06:06 +0100 Subject: [PATCH] Lib: small refactoring around js exception printing --- lib/js_of_ocaml/js.ml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/js_of_ocaml/js.ml b/lib/js_of_ocaml/js.ml index e9972add32..9422def2c2 100644 --- a/lib/js_of_ocaml/js.ml +++ b/lib/js_of_ocaml/js.ml @@ -812,15 +812,16 @@ let parseFloat (s : js_string t) : number_t = let s = Unsafe.fun_call Unsafe.global##.parseFloat [| Unsafe.inject s |] in if isNaN s then failwith "parseFloat" else s -let _ = - Printexc.register_printer (function - | Js_error.Exn e -> Some (Js_error.to_string e) - | _ -> None) - let _ = Printexc.register_printer (fun e -> - let e : < .. > t = Obj.magic e in - if instanceof e array_constructor then None else Some (to_string e##toString)) + if instanceof (Obj.magic e : < .. > t) error_constr + then + let e = Js_error.of_error (Obj.magic e : error t) in + Some (Js_error.to_string e) + else + match e with + | Js_error.Exn e -> Some (Js_error.to_string e) + | _ -> None) let export_js (field : js_string t) x = Unsafe.set