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

Async handles and Errors #233

Closed
fivdi opened this issue Mar 5, 2018 · 13 comments
Closed

Async handles and Errors #233

fivdi opened this issue Mar 5, 2018 · 13 comments

Comments

@fivdi
Copy link

fivdi commented Mar 5, 2018

Async handles can be used to "wakeup" the event loop and get a callback called from another thread. However, if the callback throws an error it doesn't appear to be possible to handle the error and have it displayed to the user.

An example of such an async handle can be seen here. This async handle is initialized to call DispatchEvent when told to do so once per second. The callback is called by DispatchEvent. If the callback throws an error what needs to be done to display the error to the user?

@mhdawson
Copy link
Member

mhdawson commented Mar 6, 2018

Thanks for the test case, this will help investigate and come up with an solution.

@mhdawson
Copy link
Member

Believe these are related: nodejs/node#15371

@mhdawson
Copy link
Member

mhdawson commented Mar 18, 2018

Made some progress on the plane today. Likely needs 2 PRs. One to fix up escaping of handles when the handle is undefined and then one to add napi_throw_fatal. Managed to get the test case to throw the expected error but still have work to validate what I have makes sense and then generate tests.

@fivdi thanks for the test case it was very helpful.

@mhdawson
Copy link
Member

This will add the function needed to get the exception to come out: nodejs/node#19337, but there is still another fix needed for the right exception to come out in this test case. I'll work on the PR for that.

mhdawson added a commit to nodejs/node that referenced this issue Mar 18, 2018
The node-addon-api module was calling escape on undefined
which would fail. Instead of forcing a check in all consumers
of napi_escape_handle accept undefined and simply return
it as it does not need to be escaped.

Refs: nodejs/node-addon-api#233
@mhdawson
Copy link
Member

mhdawson commented Mar 18, 2018

PR to address escape issue that was preventing the right exception from coming out.

nodejs/node#19434

EDIT: Turns out this was incorrect, so ignore.

@mhdawson
Copy link
Member

Once the 2 PRs above land we can look at the PR to add a method in node-addon-api to be able to through an exception and validate the test case in this issue passes.

@mhdawson
Copy link
Member

mhdawson commented Apr 3, 2018

#245 along with the earlier PR (nodejs/node#19337).

Will let you get the correct exception if you use:

napi_fatal_exception(env, e.Value());

Next step will be to add function to throw the fatal exception with node-addon-api itself along with a test.

@mhdawson
Copy link
Member

mhdawson commented Apr 3, 2018

@fivdi I think we'll need a test case added to the node-addon-api test suite which is pretty much what you had. Do you want to contribute a PR to add it to the test suite ?

@fivdi
Copy link
Author

fivdi commented Apr 3, 2018

Do you want to contribute a PR to add it to the test suite ?

@mhdawson I'll give it a go. When would the test be needed?

@mhdawson
Copy link
Member

mhdawson commented Apr 4, 2018

There is no fixed time when it would be needed, but sooner than later would be better so that we have test coverage. You can writ it using napi_fatal_exception and then can change that to the node-add-api method when its available.

mhdawson added a commit that referenced this issue Apr 10, 2018
If an exception is pending from Call Or MakeCallback on
FunctionReference the return value may be nullptr.
Check for a pending exception and don't try to escape in these cases.

PR-URL: #245
Refs: #233
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
@mhdawson
Copy link
Member

I just committed, #245. You should now be able to build the test case using napi_fatal_exception(env, e.Value()); and it should pass with the latest node-addon-api.

@mhdawson
Copy link
Member

@fivdi do you think you'll still get to this or should I close the issue?

@fivdi
Copy link
Author

fivdi commented Nov 28, 2018

@mhdawson please close the issue

kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this issue Aug 24, 2022
If an exception is pending from Call Or MakeCallback on
FunctionReference the return value may be nullptr.
Check for a pending exception and don't try to escape in these cases.

PR-URL: nodejs/node-addon-api#245
Refs: nodejs/node-addon-api#233
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this issue Aug 26, 2022
If an exception is pending from Call Or MakeCallback on
FunctionReference the return value may be nullptr.
Check for a pending exception and don't try to escape in these cases.

PR-URL: nodejs/node-addon-api#245
Refs: nodejs/node-addon-api#233
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this issue Sep 19, 2022
If an exception is pending from Call Or MakeCallback on
FunctionReference the return value may be nullptr.
Check for a pending exception and don't try to escape in these cases.

PR-URL: nodejs/node-addon-api#245
Refs: nodejs/node-addon-api#233
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this issue Aug 11, 2023
If an exception is pending from Call Or MakeCallback on
FunctionReference the return value may be nullptr.
Check for a pending exception and don't try to escape in these cases.

PR-URL: nodejs/node-addon-api#245
Refs: nodejs/node-addon-api#233
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
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

No branches or pull requests

2 participants