Skip to content
Permalink
Browse files

report: refactor triggerReport()

This commit fixes the triggerReport() argument validation. The
existing test is also updated, as it was not passing the Error
object to triggerReport().

PR-URL: #26268
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
cjihrig authored and addaleax committed Feb 22, 2019
1 parent b0c310d commit 8e2cc5e440a5fdcc495feeb9c0f884fac7897825
Showing with 17 additions and 20 deletions.
  1. +11 −13 lib/internal/process/report.js
  2. +4 −5 src/node_report_module.cc
  3. +2 −2 test/node-report/test-api-pass-error.js
@@ -75,20 +75,18 @@ const report = {
},
triggerReport(file, err) {
emitExperimentalWarning('report');
if (err == null) {
if (file == null) {
return nr.triggerReport(new ERR_SYNTHETIC().stack);
}
if (typeof file !== 'string')
throw new ERR_INVALID_ARG_TYPE('file', 'String', file);
return nr.triggerReport(file, new ERR_SYNTHETIC().stack);
}
if (typeof err !== 'object')
throw new ERR_INVALID_ARG_TYPE('err', 'Object', err);
if (file == null)
return nr.triggerReport(err.stack);
if (typeof file !== 'string')

if (typeof file === 'object' && file !== null) {
err = file;
file = undefined;
} else if (file !== undefined && typeof file !== 'string') {
throw new ERR_INVALID_ARG_TYPE('file', 'String', file);
} else if (err === undefined) {
err = new ERR_SYNTHETIC();
} else if (err === null || typeof err !== 'object') {
throw new ERR_INVALID_ARG_TYPE('err', 'Object', err);
}

return nr.triggerReport(file, err.stack);
},
getReport(err) {
@@ -48,12 +48,11 @@ void TriggerReport(const FunctionCallbackInfo<Value>& info) {
std::string filename;
Local<String> stackstr;

if (info.Length() == 1) {
stackstr = info[0].As<String>();
} else {
CHECK_EQ(info.Length(), 2);
stackstr = info[1].As<String>();

if (info[0]->IsString())
filename = *String::Utf8Value(isolate, info[0]);
stackstr = info[1].As<String>();
}

filename = TriggerNodeReport(
isolate, env, "JavaScript API", __func__, filename, stackstr);
@@ -7,8 +7,8 @@ const assert = require('assert');
if (process.argv[2] === 'child') {
try {
throw new Error('Testing error handling');
} catch {
process.report.triggerReport();
} catch (err) {
process.report.triggerReport(err);
}
} else {
const helper = require('../common/report.js');

0 comments on commit 8e2cc5e

Please sign in to comment.
You can’t perform that action at this time.