Skip to content

Commit

Permalink
report: use triggerReport() to handle exceptions
Browse files Browse the repository at this point in the history
This commit uses the triggerReport() binding to handle
uncaught exceptions and removes the custom onUncaughtException
function.

PR-URL: #26386
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and BridgeAR committed Mar 4, 2019
1 parent 851a691 commit b2c77ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
5 changes: 4 additions & 1 deletion lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
30 changes: 7 additions & 23 deletions src/node_report_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b2c77ec

Please sign in to comment.