Skip to content

A Napi::Error may become invalid if it is thrown out of a handle scope #31

Closed
@jasongin

Description

@jasongin

When a Napi::Error is constructed, it acquires a handle to a JS error object via napi_get_and_clear_last_exception(). Then the Napi::Error instance is intended to be thrown and caught as a C++ exception. But if any stack frame between where it is thrown and where it is caught has set up a handle scope, then the error object handle gets released as the exception propagates up the stack.

One way to resolve this is whenever using handle scopes be sure to catch any Napi::Error and escape it from the scope before re-throwing it. But this makes it difficult to use handle scopes correctly and therefore would result in bugs that only occur in exception conditions. So, not a good solution.

Instead, the Error class can be changed to acquire a persistent reference to the error object, instead of just a handle. I'm working on this.

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