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

Add a flag NODEJS_CATCH_REJECTION to control handling of unhandled rejections in node #9061

Merged
merged 3 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,18 @@ var EXCEPTION_CATCHING_WHITELIST = [];
// longer do that, and exceptions work normally, which can be useful for libraries
// or programs that don't need exit() to work.

// For more explanations of this option, please visit
// https://github.com/emscripten-core/emscripten/wiki/Asyncify
// Emscripten uses an ExitStatus exception to halt when exit() is called.
// With this option, we prevent that from showing up as an unhandled
// exception.
var NODEJS_CATCH_EXIT = 1;

// Catch unhandled rejections in node. Without this, node may print the error,
// and that this behavior will change in future node, wait a few seconds, and
// then exit with 0 (which hides the error if you don't read the log). With
// this, we catch any unhandled rejection and throw an actual error, which will
// make the process exit immediately with a non-0 return code.
var NODEJS_CATCH_REJECTION = 1;

// Whether to enable asyncify transformation
// This allows to inject some async functions to the C code that appear to be sync
// e.g. emscripten_sleep
Expand Down
5 changes: 3 additions & 2 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ if (ENVIRONMENT_IS_NODE) {
}
});
#endif
// Currently node will swallow unhandled rejections, but this behavior is
// deprecated, and in the future it will exit with error status.

#if NODEJS_CATCH_REJECTION
process['on']('unhandledRejection', abort);
#endif

Module['quit'] = function(status) {
process['exit'](status);
Expand Down