Skip to content

Commit b2c77ec

Browse files
cjihrigBridgeAR
authored andcommitted
report: use triggerReport() to handle exceptions
This commit uses the triggerReport() binding to handle uncaught exceptions and removes the custom onUncaughtException function. PR-URL: #26386 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 851a691 commit b2c77ec

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

lib/internal/process/execution.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ function createFatalException() {
116116
report.syncConfig(config, false);
117117
if (Array.isArray(config.events) &&
118118
config.events.includes('exception')) {
119-
report.onUnCaughtException(er ? er.stack : undefined);
119+
report.triggerReport(er ? er.message : 'Exception',
120+
'Exception',
121+
null,
122+
er ? er.stack : undefined);
120123
}
121124
}
122125
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.

lib/internal/process/report.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const report = {
8787
throw new ERR_INVALID_ARG_TYPE('err', 'Object', err);
8888
}
8989

90-
return nr.triggerReport(file, err.stack);
90+
return nr.triggerReport('JavaScript API', 'API', file, err.stack);
9191
},
9292
getReport(err) {
9393
emitExperimentalWarning('report');

src/node_report_module.cc

+7-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ using v8::V8;
3535
using v8::Value;
3636

3737
// Internal/static function declarations
38-
void OnUncaughtException(const FunctionCallbackInfo<Value>& info);
3938
static void Initialize(Local<Object> exports,
4039
Local<Value> unused,
4140
Local<Context> context);
@@ -48,14 +47,16 @@ void TriggerReport(const FunctionCallbackInfo<Value>& info) {
4847
std::string filename;
4948
Local<String> stackstr;
5049

51-
CHECK_EQ(info.Length(), 2);
52-
stackstr = info[1].As<String>();
50+
CHECK_EQ(info.Length(), 4);
51+
String::Utf8Value message(isolate, info[0].As<String>());
52+
String::Utf8Value trigger(isolate, info[1].As<String>());
53+
stackstr = info[3].As<String>();
5354

54-
if (info[0]->IsString())
55-
filename = *String::Utf8Value(isolate, info[0]);
55+
if (info[2]->IsString())
56+
filename = *String::Utf8Value(isolate, info[2]);
5657

5758
filename = TriggerNodeReport(
58-
isolate, env, "JavaScript API", __func__, filename, stackstr);
59+
isolate, env, *message, *trigger, filename, stackstr);
5960
// Return value is the report filename
6061
info.GetReturnValue().Set(
6162
String::NewFromUtf8(isolate, filename.c_str(), v8::NewStringType::kNormal)
@@ -79,22 +80,6 @@ void GetReport(const FunctionCallbackInfo<Value>& info) {
7980
.ToLocalChecked());
8081
}
8182

82-
// Callbacks for triggering report on uncaught exception.
83-
// Calls triggered from JS land.
84-
void OnUncaughtException(const FunctionCallbackInfo<Value>& info) {
85-
Environment* env = Environment::GetCurrent(info);
86-
Isolate* isolate = env->isolate();
87-
HandleScope scope(isolate);
88-
std::string filename;
89-
std::shared_ptr<PerIsolateOptions> options = env->isolate_data()->options();
90-
91-
// Trigger report if requested
92-
if (options->report_uncaught_exception) {
93-
TriggerNodeReport(
94-
isolate, env, "exception", __func__, filename, info[0].As<String>());
95-
}
96-
}
97-
9883
// Signal handler for report action, called from JS land (util.js)
9984
void OnUserSignal(const FunctionCallbackInfo<Value>& info) {
10085
Environment* env = Environment::GetCurrent(info);
@@ -239,7 +224,6 @@ static void Initialize(Local<Object> exports,
239224
std::shared_ptr<PerIsolateOptions> options = env->isolate_data()->options();
240225
env->SetMethod(exports, "triggerReport", TriggerReport);
241226
env->SetMethod(exports, "getReport", GetReport);
242-
env->SetMethod(exports, "onUnCaughtException", OnUncaughtException);
243227
env->SetMethod(exports, "onUserSignal", OnUserSignal);
244228
env->SetMethod(exports, "syncConfig", SyncConfig);
245229
}

0 commit comments

Comments
 (0)