Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-11 22:46:43 +0300
committerBeth Griggs <Bethany.Griggs@uk.ibm.com>2019-10-15 21:43:53 +0300
commitb43d7e8f429fd7bc6e44f7e4d1e7a48a8b150908 (patch)
treef63412dedf9c55edaccdb9e8585837dda1a9390c /src
parentc285e694e2444d1bee5b5dcb1ea414b7068d04e4 (diff)
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.cc13
-rw-r--r--src/node_options.cc13
-rw-r--r--src/node_options.h1
3 files changed, 25 insertions, 2 deletions
diff --git a/src/node.cc b/src/node.cc
index 079bad24286..7c0118758df 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 79dff7adbf9..e50fd786929 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 0345e0869aa..389fec2f2e9 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;