Skip to content

Async handles and Errors #233

Description

@fivdi

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?

Activity

  1. mhdawson commented on Mar 6, 2018

    @mhdawson
    Member

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

  2. mhdawson commented on Mar 18, 2018

    @mhdawson
    Member

    Believe these are related: nodejs/node#15371

  3. mhdawson commented on Mar 18, 2018

    @mhdawson
    Member

    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.

  4. mhdawson commented on Mar 18, 2018

    @mhdawson
    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.

  5. added a commit that references this issue on Mar 18, 2018
  6. mhdawson commented on Mar 18, 2018

    @mhdawson
    Member

    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.

  7. mhdawson commented on Mar 18, 2018

    @mhdawson
    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.

  8. mhdawson commented on Apr 3, 2018

    @mhdawson
    Member

    #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.

  9. mhdawson commented on Apr 3, 2018

    @mhdawson
    Member

    @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 ?

  10. fivdi commented on Apr 3, 2018

    @fivdi
    Author

    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?

  11. mhdawson commented on Apr 4, 2018

    @mhdawson
    Member

    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.

  12. added a commit that references this issue on Apr 10, 2018
  13. mhdawson commented on Apr 10, 2018

    @mhdawson
    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.

  14. mhdawson commented on Nov 27, 2018

    @mhdawson
    Member

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

  15. fivdi commented on Nov 28, 2018

    @fivdi
    Author

    @mhdawson please close the issue

  16. added a commit that references this issue on Aug 24, 2022
  17. added a commit that references this issue on Aug 26, 2022
  18. added a commit that references this issue on Sep 19, 2022
  19. added a commit that references this issue on Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions