-
Notifications
You must be signed in to change notification settings - Fork 34
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
napi_create_int32 does not return napi_pending_exception #356
Comments
I believe it started as an effort to allow you to call functions which would be needed to do minimal cleanup in the face of a pending exception. This may have been extended to cases were the methods cannot throw an exception themselves. Do you have some sample code that shows where the exception was generated but then only later you have it returned? |
Just to be clear, I do not consider this as a bug, but more of inconsistent behavior, which was weird to debug.
Technically, wrap_callback_B should check for pending exception and return early, but it didn't because, well, I did not expect it would be called with a pending exception. Instead I got invalid statuses somewhere in the middle of wrap_callback, when the napi_create_buffer failed. |
Thanks for the detail. I do see why the first call passing, but the second one not could be confusing. I assume napi_call_function would have returned that there was a pending exception? My guess is that would have been the right place to check and return, but I'm not quite sure from what you've provided above. |
Exactly this.
Yes, napi_call_function (A), did return pending exception and const wrap = require('wrapper');
const w = new wrap.wrap();
w.on('eventA', () => throw new Error());
w.on('eventB', () => console.log('B'));
// At some point eventA and eventB are called in the same process loop
setInterval(() => w.process(), 100); Anyway, getting back to the point. Is this discrepancy between napi_create_X functions a feature or a bug? |
It is a "feature" that we have chosen that you can call some API functions even though an exception is pending. This was to allow for minimal cleanup to be done if possible. I will take a look to see if we properly document that. |
I'm going to update the docs to reflect the current behavior as they don't explain the case where one is already pending when you call a method. I won't document the specific methods yet as I'm not sure we want to commit to which ones can/can not be called. |
Refs: nodejs/abi-stable-node#356 Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour.
Created nodejs/node#25339 to clarify behaviour in the docs |
Alright, thanks. Also do you have any suggestion if there's a way for a C function to force Node.js handle pending exception, without returning? Sort of recursive node.js core loop handing? In my scenario I can't control when |
One thing I can think of would be to check for a pending exception and then calling |
Alright, thank you for the help. As far as I'm concerned, this issue can be closed. |
@GiedriusM thanks for your help/discussion. Closing for now. |
Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour. PR-URL: #25339 Refs: nodejs/abi-stable-node#356 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour. PR-URL: #25339 Refs: nodejs/abi-stable-node#356 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour. PR-URL: nodejs#25339 Refs: nodejs/abi-stable-node#356 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour. PR-URL: #25339 Refs: nodejs/abi-stable-node#356 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour. PR-URL: #25339 Refs: nodejs/abi-stable-node#356 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Document current behaviour where some methods can be called when an exception is pending, while others cannot and explain the behaviour. PR-URL: #25339 Refs: nodejs/abi-stable-node#356 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
I noticed that
napi_create_int32
(and other "Functions to convert from C types to N-API") do not returnnapi_pending_exception
when one is actually present, howevernapi_create_buffer
(and other "Object Creation Functions") do.Is this inconsistency intended? According to this old post it should not (napi_create_number is checked as well as napi_create_buffer). Could not find any newer information, though.
Got really confused when the code started failing in the middle or variable creation :/
The text was updated successfully, but these errors were encountered: