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

Unable to process the null exceptions of the Node.js 14.x REPL #1239

Closed
mmomtchev opened this issue Nov 23, 2022 · 2 comments
Closed

Unable to process the null exceptions of the Node.js 14.x REPL #1239

mmomtchev opened this issue Nov 23, 2022 · 2 comments

Comments

@mmomtchev
Copy link

mmomtchev commented Nov 23, 2022

FATAL ERROR: Error::Error napi_define_properties
 1: 0xa3ac30 node::Abort() [node]
 2: 0x970199 node::FatalError(char const*, char const*) [node]
 3: 0x9701a2  [node]
 4: 0xa07f1b napi_fatal_error [node]

This part of the code

if (status != napi_ok) {
can cause a crash in Node.js 14.x in REPL - I was not able to reproduce in a later version and maybe it does not happen.

The type-ahead displaying in REPL has some very special peculiarities and constructors can fail - I suppose because it uses an eval context without globals - which it can detect, catch and ignore. In particular, a constructor can throw a null value. In this case, node-addon-api will be unable to create an Error object - it will fail with the above error.

I won't bother with a minimal reproduction, since it probably won't be fixed anyway, but if you want to see it:

nvm use 14.x
git clone https://github.com/mmomtchev/pymport
npm install
node-pre-gyp configure --debug
node-pre-gyp build
node
> const { PyObject } = require('.');
const a = PyObject.fromJS(4);
> a.co     // Start typing a.constr and it will crash, if you copy&paste a.constr everything will be ok

The crash happens when calling FunctionReference::New() - napi_new_instance throws null and the wrapping of the error object in the code cited above fails.

If you short-circuit the error object wrapping, the Node.js REPL correctly catches the null exception and continues without error.

Bypassing node-addon-api and manually re-implementing FunctionReference::New() also fixes the issue.

@JckXia
Copy link
Member

JckXia commented Nov 24, 2022

I believe this was related to #1000 that was specific to Node.js 14 (fixed in 16 and later).

I am not too certain of the mechanism behind this but it was an issue with V8 IIRC. We attempted to backport that fix into the Node14 line but there was quite a bit of change required so we've abandoned the fix.

@mmomtchev
Copy link
Author

Closing as a duplicate

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

2 participants