From 2755471bf3ce35a14cb348d4fbf0d34779426e66 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Tue, 12 Mar 2019 11:07:35 +0100 Subject: [PATCH] src: print error before aborting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of fatal errors, first print the error before aborting in case the process should abort on uncaught exceptions. PR-URL: https://github.com/nodejs/node/pull/26599 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina Reviewed-By: Matheus Marchini Reviewed-By: Michael Dawson Reviewed-By: Сковорода Никита Андреевич Reviewed-By: Sakthipriyan Vairamani --- src/node_errors.h | 16 ++++++++++++---- src/node_task_queue.cc | 5 +++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/node_errors.h b/src/node_errors.h index 4d6e1ab42d4d5d..b04a347f1e7fe0 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -14,10 +14,14 @@ namespace node { +using v8::Local; +using v8::Message; +using v8::Value; + enum ErrorHandlingMode { CONTEXTIFY_ERROR, FATAL_ERROR, MODULE_ERROR }; void AppendExceptionLine(Environment* env, - v8::Local er, - v8::Local message, + Local er, + Local message, enum ErrorHandlingMode mode); [[noreturn]] void FatalError(const char* location, const char* message); @@ -27,9 +31,13 @@ void PrintErrorString(const char* format, ...); void ReportException(Environment* env, const v8::TryCatch& try_catch); +void ReportException(Environment* env, + Local er, + Local message); + void FatalException(v8::Isolate* isolate, - v8::Local error, - v8::Local message); + Local error, + Local message); // Helpers to construct errors similar to the ones provided by // lib/internal/errors.js. diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc index b14c806dec04be..b832a66d8b14ff 100644 --- a/src/node_task_queue.cc +++ b/src/node_task_queue.cc @@ -110,11 +110,12 @@ static void SetPromiseRejectCallback( static void TriggerFatalException(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); Environment* env = Environment::GetCurrent(isolate); + Local exception = args[0]; + Local message = Exception::CreateMessage(isolate, exception); if (env != nullptr && env->abort_on_uncaught_exception()) { + ReportException(env, exception, message); Abort(); } - Local exception = args[0]; - Local message = Exception::CreateMessage(isolate, exception); FatalException(isolate, exception, message); }