-
Notifications
You must be signed in to change notification settings - Fork 465
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
Exception handling broken with instance accessors #621
Comments
The problem is that, if If there's a pending exception we should always honour it and get back to the engine ASAP, no matter that the Ideally we'd fix this in N-API core and always return As a framework on top of N-API, I believe we can correct at the above-linked place what I believe is a mistake we made in N-API and treat any non- @nodejs/n-api @tniessen WDYT? |
In the case of the chain of calls illustrated in @blagoev's code, the site of the mistake is |
I agree that having the At the same time, the N-API docs state very clearly how we should be handling other errors codes if there is a pending exception, and it seems that we don't do that correctly in node-addon-api, so we should fix that. |
@tniessen IIRC we added the statement to the docs regarding non- I'm not sure how we should handle the situation where the return code is non- |
I would expect this behavior: Do not replace the exception. If users want to chain exceptions, they can do that in their addon. |
If I may express my opinion. I would expect the exception to be the same as if the code was called from JS. I tried to demonstrate that in the sample, but I think I should have been more clear on it. If you do My way of thinking of doing this, or any other thing for that matter would be, if the code is written in JS only and if it is written in native only it should behave the same. One way of defining a general approach is possibly this. If a cheers |
Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: nodejs#621
Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: nodejs#621
Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: nodejs/node-addon-api#621 PR-URL: nodejs/node-addon-api#629 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: nodejs/node-addon-api#621 PR-URL: nodejs/node-addon-api#629 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: nodejs/node-addon-api#621 PR-URL: nodejs/node-addon-api#629 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: nodejs/node-addon-api#621 PR-URL: nodejs/node-addon-api#629 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
Hey folks,
While migrating Realm to NAPI we encountered this issue.
To demonstrate it I have forked the node-addon-examples and modified one of them here
https://github.com/blagoev/node-addon-examples/tree/master/6_object_wrap/node-addon-api
There is an issue in the example code, but mainly an issue with exception handling when instance accessors are invoked from C++. I tried to comment as much as possible.
and the JS code
Here is an example/possible fix to this issue
Change this in your
napi-inl.h
I did not do a PR since this may be happening somewhere else and there may be some better way to do it which fixes multiple places
I would love to have this fixed upstream so we can skip forking napi-inl.h in our project.
cheers
The text was updated successfully, but these errors were encountered: