You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
create test.js
constfsevents=require('fsevents');conststop=fsevents.watch(__dirname,()=>{x++;// reference error: x not defined});setTimeout(()=>{stop();},60000);
node test.js
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?
The text was updated successfully, but these errors were encountered:
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
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
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 errorThe logged error is:
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:
test.js
node test.js
touch abc.txt
to trigger the watcher and observe the confusing errorWorkaround / 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?
The text was updated successfully, but these errors were encountered: