-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
Closed
Description
- Version: v9.8.0 (Docker [email protected] image)
- Platform: Linux a5d5c8becf83 4.4.0-104-generic src: fix unaligned access in ucs2 string encoder #127-Ubuntu SMP Mon Dec 11 12:16:42 UTC 2017 x86_64 GNU/Linux
- Subsystem: addons n-api
When using N-API, if an exception is thrown during the module's Init, it is not reported during the require() call and might not be reported at all.
If you modify the N-API hello world sample code to throw an error during Init:
napi_value Init(napi_env env, napi_value exports) {
napi_status status;
napi_property_descriptor desc = DECLARE_NAPI_METHOD("hello", Method);
status = napi_define_properties(env, exports, 1, &desc);
assert(status == napi_ok);
- return exports;
+ napi_throw_error(env, "CODE", "Test error");
+ printf("Ran error code\n");
+ return nullptr;
}
...the error itself is not thrown until the hello()
method call:
root@a5d5c8becf83:/app/pure-napi# node hello.js
Ran error code
/app/pure-napi/hello.js:3
console.log(addon.hello()); // 'world'
^
Error [CODE]: Test error
at Object.Module._extensions..node (module.js:678:18)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:501:12)
at Function.Module._load (module.js:493:3)
at Module.require (module.js:593:17)
at require (internal/module.js:11:18)
at bindings (/app/pure-napi/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/app/pure-napi/hello.js:1:94)
at Module._compile (module.js:649:30)
at Object.Module._extensions..js (module.js:660:10)
Further, if the method is not called, the error isn't reported at all.
Metadata
Metadata
Assignees
Labels
No labels