Skip to content

Commit 44ef0bb

Browse files
authored
Lib: small refactoring around js exception printing (#1743)
1 parent 22a0945 commit 44ef0bb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/js_of_ocaml/js.ml

+8-7
Original file line numberDiff line numberDiff line change
@@ -812,15 +812,16 @@ let parseFloat (s : js_string t) : number_t =
812812
let s = Unsafe.fun_call Unsafe.global##.parseFloat [| Unsafe.inject s |] in
813813
if isNaN s then failwith "parseFloat" else s
814814

815-
let _ =
816-
Printexc.register_printer (function
817-
| Js_error.Exn e -> Some (Js_error.to_string e)
818-
| _ -> None)
819-
820815
let _ =
821816
Printexc.register_printer (fun e ->
822-
let e : < .. > t = Obj.magic e in
823-
if instanceof e array_constructor then None else Some (to_string e##toString))
817+
if instanceof (Obj.magic e : < .. > t) error_constr
818+
then
819+
let e = Js_error.of_error (Obj.magic e : error t) in
820+
Some (Js_error.to_string e)
821+
else
822+
match e with
823+
| Js_error.Exn e -> Some (Js_error.to_string e)
824+
| _ -> None)
824825

825826
let export_js (field : js_string t) x =
826827
Unsafe.set

0 commit comments

Comments
 (0)