Skip to content

Commit 2755471

Browse files
committed
src: print error before aborting
In case of fatal errors, first print the error before aborting in case the process should abort on uncaught exceptions. PR-URL: #26599 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent ffd2df0 commit 2755471

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/node_errors.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
namespace node {
1616

17+
using v8::Local;
18+
using v8::Message;
19+
using v8::Value;
20+
1721
enum ErrorHandlingMode { CONTEXTIFY_ERROR, FATAL_ERROR, MODULE_ERROR };
1822
void AppendExceptionLine(Environment* env,
19-
v8::Local<v8::Value> er,
20-
v8::Local<v8::Message> message,
23+
Local<Value> er,
24+
Local<Message> message,
2125
enum ErrorHandlingMode mode);
2226

2327
[[noreturn]] void FatalError(const char* location, const char* message);
@@ -27,9 +31,13 @@ void PrintErrorString(const char* format, ...);
2731

2832
void ReportException(Environment* env, const v8::TryCatch& try_catch);
2933

34+
void ReportException(Environment* env,
35+
Local<Value> er,
36+
Local<Message> message);
37+
3038
void FatalException(v8::Isolate* isolate,
31-
v8::Local<v8::Value> error,
32-
v8::Local<v8::Message> message);
39+
Local<Value> error,
40+
Local<Message> message);
3341

3442
// Helpers to construct errors similar to the ones provided by
3543
// lib/internal/errors.js.

src/node_task_queue.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ static void SetPromiseRejectCallback(
110110
static void TriggerFatalException(const FunctionCallbackInfo<Value>& args) {
111111
Isolate* isolate = args.GetIsolate();
112112
Environment* env = Environment::GetCurrent(isolate);
113+
Local<Value> exception = args[0];
114+
Local<Message> message = Exception::CreateMessage(isolate, exception);
113115
if (env != nullptr && env->abort_on_uncaught_exception()) {
116+
ReportException(env, exception, message);
114117
Abort();
115118
}
116-
Local<Value> exception = args[0];
117-
Local<Message> message = Exception::CreateMessage(isolate, exception);
118119
FatalException(isolate, exception, message);
119120
}
120121

0 commit comments

Comments
 (0)