Swallow exceptions in terminating environments… #185
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…triggered by
nsfw
async operations.This fixes #184 and is a product of the discussion in that issue.
There appears to be an exception caused by the following chain of events:
start
called on an NSFW instance, returning a promiseworker.terminate()
or the equivalent)start
promise resolvesOrdinarily, this is a fatal error:
NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS
was created to enable a mode where such exceptions are caught and swallowed so that they don't bring the entire process down.This test in N-API itself may be useful to consult: it creates a worker, start an async operation, terminates the worker, then triggers an exception from the C++ code. The two “swallow exceptions” modes are the only ones in which the process is meant to keep going after such a failure.
I need this in an Electron environment — specifically loading
nsfw
in a renderer process, where a simple page reload is enough to create a terminating environment like the one in that test case.