diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-03-11 20:46:43 +0100 |
---|---|---|
committer | Beth Griggs <Bethany.Griggs@uk.ibm.com> | 2019-10-15 19:43:53 +0100 |
commit | b43d7e8f429fd7bc6e44f7e4d1e7a48a8b150908 (patch) | |
tree | f63412dedf9c55edaccdb9e8585837dda1a9390c /src | |
parent | c285e694e2444d1bee5b5dcb1ea414b7068d04e4 (diff) | |
download | node-new-b43d7e8f429fd7bc6e44f7e4d1e7a48a8b150908.tar.gz |
process: add --unhandled-rejections flag
This adds a flag to define the default behavior for unhandled
rejections. Three modes exist: `none`, `warn` and `strict`. The first
is going to silence all unhandled rejection warnings. The second
behaves identical to the current default with the excetion that no
deprecation warning will be printed and the last is going to throw
an error for each unhandled rejection, just as regular exceptions do.
It is possible to intercept those with the `uncaughtException` hook
as with all other exceptions as well.
This PR has no influence on the existing `unhandledRejection` hook.
If that is used, it will continue to function as before.
PR-URL: https://github.com/nodejs/node/pull/26599
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 13 | ||||
-rw-r--r-- | src/node_options.cc | 13 | ||||
-rw-r--r-- | src/node_options.h | 1 |
3 files changed, 25 insertions, 2 deletions
diff --git a/src/node.cc b/src/node.cc index 079bad2428..7c0118758d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1370,7 +1370,8 @@ FatalTryCatch::~FatalTryCatch() { void FatalException(Isolate* isolate, Local<Value> error, - Local<Message> message) { + Local<Message> message, + bool from_promise) { HandleScope scope(isolate); Environment* env = Environment::GetCurrent(isolate); @@ -1391,9 +1392,12 @@ void FatalException(Isolate* isolate, // Do not call FatalException when _fatalException handler throws fatal_try_catch.SetVerbose(false); + Local<Value> argv[2] = { error, + Boolean::New(env->isolate(), from_promise) }; + // This will return true if the JS layer handled it, false otherwise MaybeLocal<Value> caught = fatal_exception_function.As<Function>()->Call( - env->context(), process_object, 1, &error); + env->context(), process_object, arraysize(argv), argv); if (fatal_try_catch.HasTerminated()) return; @@ -1418,6 +1422,11 @@ void FatalException(Isolate* isolate, } } +void FatalException(Isolate* isolate, + Local<Value> error, + Local<Message> message) { + FatalException(isolate, error, message, false /* from_promise */); +} void FatalException(Isolate* isolate, const TryCatch& try_catch) { // If we try to print out a termination exception, we'd just get 'null', diff --git a/src/node_options.cc b/src/node_options.cc index 79dff7adbf..e50fd78692 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -39,6 +39,14 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { if (syntax_check_only && has_eval_string) { errors->push_back("either --check or --eval can be used, not both"); } + + if (!unhandled_rejections.empty() && + unhandled_rejections != "strict" && + unhandled_rejections != "warn" && + unhandled_rejections != "none") { + errors->push_back("invalid value for --unhandled-rejections"); + } + debug_options->CheckOptions(errors); } @@ -155,6 +163,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "show stack traces on process warnings", &EnvironmentOptions::trace_warnings, kAllowedInEnvironment); + AddOption("--unhandled-rejections", + "define unhandled rejections behavior. Options are 'strict' (raise " + "an error), 'warn' (enforce warnings) or 'none' (silence warnings)", + &EnvironmentOptions::unhandled_rejections, + kAllowedInEnvironment); AddOption("--check", "syntax check script without executing", diff --git a/src/node_options.h b/src/node_options.h index 0345e0869a..389fec2f2e 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -84,6 +84,7 @@ class EnvironmentOptions : public Options { bool trace_deprecation = false; bool trace_sync_io = false; bool trace_warnings = false; + std::string unhandled_rejections; std::string userland_loader; bool syntax_check_only = false; |