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

Uncaught exception in watcher's callback leads to confusing error message (Assertion failed: napi_call_function...) #370

Open
jakub-g opened this issue Nov 29, 2021 · 0 comments

Comments

@jakub-g
Copy link
Contributor

jakub-g commented Nov 29, 2021

Issue

When the callback provided to .watch throws an exception for whatever reason, fsevents 1) crashes node process with a confusing native error message (because uncaught exception is thrown and nowhere handled), and 2) doesn't say anything about the original underlying JS error

The logged error is:

Assertion failed: (napi_call_function(env, recv, callback, 3, args, &recv) == napi_ok), function fse_dispatch_event, file ../src/fsevents.c, line 151.

which leads to think there's some issue with fsevents in native code or file system, while it's actually a boring error in the user's JS code.

Min repro:

  1. create test.js
const fsevents = require('fsevents');
const stop = fsevents.watch(__dirname, () => {
    x++; // reference error: x not defined
});
setTimeout(() => {
    stop();
}, 60000);
  1. node test.js
  2. touch abc.txt to trigger the watcher and observe the confusing error

Workaround / solution

Wrapping the callback with try/catch fixes this. Perhaps this should be documented? (I can raise a PR).

But I think this deserves a fix in the module itself, although I'm not sure if this is feasible?

@jakub-g jakub-g changed the title Error in callback leads to confusing error message (Assertion failed: napi_call_function...) Error in watcher's callback leads to confusing error message (Assertion failed: napi_call_function...) Nov 29, 2021
@jakub-g jakub-g changed the title Error in watcher's callback leads to confusing error message (Assertion failed: napi_call_function...) Uncaught exception in watcher's callback leads to confusing error message (Assertion failed: napi_call_function...) Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant