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

Fix reporting of API error messages #43

Merged
merged 1 commit into from
Jun 6, 2017
Merged

Conversation

jasongin
Copy link
Member

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

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) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

@jasongin
Copy link
Member Author

jasongin commented Jun 5, 2017

@addaleax @boingoing @mhdawson Can someone review this? Thanks!

Copy link

@boingoing boingoing left a 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.

@jasongin jasongin merged commit 92f362a into nodejs:master Jun 6, 2017
@jasongin jasongin deleted the error branch June 6, 2017 17:16
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

Successfully merging this pull request may close these issues.

3 participants