Skip to content
New issue

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

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

Already on GitHub? # to your account

Using js_of_ocaml generated code in node top level alters node's default error handling #1277

Open
johnwhitington opened this issue May 28, 2022 · 2 comments
Labels

Comments

@johnwhitington
Copy link

Consider a blank a.ml

let _ = 1

Now, in node, an error normally allows us to resume, putting us back at the prompt:

$ node
Welcome to Node.js v18.0.0.
Type ".help" for more information.
> b
Uncaught ReferenceError: b is not defined
>

But after requiring our new a.js operation, an error completely unrelated to the js_of_ocaml code causes the whole node process to exit:

$ node
Welcome to Node.js v18.0.0.
Type ".help" for more information.
> const a = require('./a.js');
undefined
> b
/Users/john/Desktop/jsootest/a.js:300
throw b}function
^

[ReferenceError: b is not defined]
$

Is this expected? I should say this also happens with my real project, which has an exports.ml like this:

open Js_of_ocaml

let _ =
  Js.export "cpdflib"
    (object%js
       (* CHAPTER 0. Preliminaries *)
       method getLastError = Cpdflib.getLastError ()
       method getLastErrorString = Cpdflib.getLastErrorString ()
......

I understood that would make it usable from node via require. It is usable, but it has this odd error behaviour.

I'm using js_of_ocaml 4.0.0 and node 18.0.0.

@hhugo
Copy link
Member

hhugo commented May 28, 2022

It is expected and due to

function caml_setup_uncaught_exception_handler() {
. Maybe we should only have that logic turned on for standalone programs.

@johnwhitington
Copy link
Author

Thanks for the explanation. Yes, it would be a useful option.

I'm very new to JavaScript, so I don't know how common it is to use the REPL, or whether libraries commonly have non-modular effects like this.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants