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

[FEATURE REQUEST] Documentation for --enable=with-js-error along with caml_js_error_of_exception #1044

Open
Lupus opened this issue Jul 27, 2020 · 2 comments

Comments

@Lupus
Copy link

Lupus commented Jul 27, 2020

Enabling with-js-error attaches fresh Error to all exceptions, and gives one ability to extract backtrace from JS error object via caml_js_error_of_exception. It's not exported from the jsoo API currently, and needs to be declared as an extern:

external js_error_of_exception :
  exn -> Js.error Js.t Js.opt = "caml_js_error_of_exception"

I've used it like this in Lwt async exception hook to log js backtrace when unhandled exception happens:

Lwt.async_exception_hook :=
    (fun e ->
       let js_backtrace =
         match Js.Opt.to_option (js_error_of_exception e) with
         | Some js_error ->
             (match Js.Optdef.to_option (js_error ##. stack) with
              | Some str -> str |> Js.to_string
              | None -> "(no stack)")
         | None -> "(no js_error attached)" in
       let err = Error.of_exn e in
       Logs.err
         (fun m ->
            m "async promise exception: %s, JS backtrace: %s"
              (Error.to_string_hum err) js_backtrace);
       exit 127)

Would be awesome to have caml_js_error_of_exception exposed in public API and have this way to get backtraces documented.

@hhugo
Copy link
Member

hhugo commented Jan 6, 2022

There is Js.js_error_of_exn

@hhugo
Copy link
Member

hhugo commented Jan 6, 2022

Introduced in #1071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants