0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

report: use triggerReport() to handle exceptions

This commit uses the triggerReport() binding to handle
uncaught exceptions and removes the custom onUncaughtException
function.

PR-URL: https://github.com/nodejs/node/pull/26386
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
cjihrig 2019-03-01 17:10:25 -05:00
parent 28db96f31c
commit 48ab54c323
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
3 changed files with 12 additions and 25 deletions

View File

@ -116,7 +116,10 @@ function createFatalException() {
report.syncConfig(config, false);
if (Array.isArray(config.events) &&
config.events.includes('exception')) {
report.onUnCaughtException(er ? er.stack : undefined);
report.triggerReport(er ? er.message : 'Exception',
'Exception',
null,
er ? er.stack : undefined);
}
}
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.

View File

@ -87,7 +87,7 @@ const report = {
throw new ERR_INVALID_ARG_TYPE('err', 'Object', err);
}
return nr.triggerReport(file, err.stack);
return nr.triggerReport('JavaScript API', 'API', file, err.stack);
},
getReport(err) {
emitExperimentalWarning('report');

View File

@ -35,7 +35,6 @@ using v8::V8;
using v8::Value;
// Internal/static function declarations
void OnUncaughtException(const FunctionCallbackInfo<Value>& info);
static void Initialize(Local<Object> exports,
Local<Value> unused,
Local<Context> context);
@ -48,14 +47,16 @@ void TriggerReport(const FunctionCallbackInfo<Value>& info) {
std::string filename;
Local<String> stackstr;
CHECK_EQ(info.Length(), 2);
stackstr = info[1].As<String>();
CHECK_EQ(info.Length(), 4);
String::Utf8Value message(isolate, info[0].As<String>());
String::Utf8Value trigger(isolate, info[1].As<String>());
stackstr = info[3].As<String>();
if (info[0]->IsString())
filename = *String::Utf8Value(isolate, info[0]);
if (info[2]->IsString())
filename = *String::Utf8Value(isolate, info[2]);
filename = TriggerNodeReport(
isolate, env, "JavaScript API", __func__, filename, stackstr);
isolate, env, *message, *trigger, filename, stackstr);
// Return value is the report filename
info.GetReturnValue().Set(
String::NewFromUtf8(isolate, filename.c_str(), v8::NewStringType::kNormal)
@ -79,22 +80,6 @@ void GetReport(const FunctionCallbackInfo<Value>& info) {
.ToLocalChecked());
}
// Callbacks for triggering report on uncaught exception.
// Calls triggered from JS land.
void OnUncaughtException(const FunctionCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
Isolate* isolate = env->isolate();
HandleScope scope(isolate);
std::string filename;
std::shared_ptr<PerIsolateOptions> options = env->isolate_data()->options();
// Trigger report if requested
if (options->report_uncaught_exception) {
TriggerNodeReport(
isolate, env, "exception", __func__, filename, info[0].As<String>());
}
}
// Signal handler for report action, called from JS land (util.js)
void OnUserSignal(const FunctionCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
@ -239,7 +224,6 @@ static void Initialize(Local<Object> exports,
std::shared_ptr<PerIsolateOptions> options = env->isolate_data()->options();
env->SetMethod(exports, "triggerReport", TriggerReport);
env->SetMethod(exports, "getReport", GetReport);
env->SetMethod(exports, "onUnCaughtException", OnUncaughtException);
env->SetMethod(exports, "onUserSignal", OnUserSignal);
env->SetMethod(exports, "syncConfig", SyncConfig);
}