-
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
Fix reporting of API error messages #43
Conversation
When a call to an N-API function caused an error for some reason other than a JS exception, the fallback error message "Error in native callback" was always reported because of incorrect logic in `Napi::Error::New()`. Then that fix exposed a bug in `napi_get_last_error_info()`, which I have fixed here and also at nodejs/node#13087
status = napi_get_last_error_info(env, &info); | ||
assert(status == napi_ok); | ||
|
||
if (status == napi_ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense? assert
+ then make the code conditional on asserted statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we encounter another error while handling an error, there's not much we can do. Probably it should be a fatal error, except we haven't exposed node::FatalError()
via N-API yet. The assert will at least indicate when something went wrong in a debug build, but in a release build the conditional allows it to continue without crashing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This came up last time this code was reviewed: #32 (comment)
Probably we should go ahead and add a napi_fatal_error()
API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a new issue to track this: #48
I don't think the current PR needs to be blocked by it.
@addaleax @boingoing @mhdawson Can someone review this? Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Agree with other comments if napi_get_last_error_info
returns an error we should fatal error.
When a call to an N-API function caused an error for some reason other than a JS exception, the fallback error message "Error in native callback" was always reported because of incorrect logic in
Napi::Error::New()
.Then that fix exposed a bug in
napi_get_last_error_info()
, which I have fixed here and also at nodejs/node#13087