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(napi): improve error propagation #1303

Merged
merged 1 commit into from Sep 14, 2022

Conversation

devongovett
Copy link
Contributor

This enables napi::Error to wrap an arbitrary JavaScript value, which may have been returned or thrown from a function. This is useful for functions that must return an napi::Result, but may have an error propagated from calling a JavaScript function. The support was partially already there for the Promise implementation, but I've extended it.

This also checks if an exception is pending after calling a JS function, and retrieves it with napi_get_and_clear_last_exception. This way, the pending exception isn't necessarily immediately thrown when returning from the native function, but can be passed elsewhere if needed (e.g. to an error callback). This is also important when calling JS functions outside the native call context (e.g. from a background thread).

@Brooooooklyn Brooooooklyn merged commit 5ba70b0 into napi-rs:main Sep 14, 2022
@Brooooooklyn Brooooooklyn changed the title Improve error propagation fix(napi): improve error propagation Sep 14, 2022
h-a-n-a pushed a commit to speedy-js/napi-rs that referenced this pull request Sep 14, 2022
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.

None yet

2 participants