diff --git a/lib/internal/process/report.js b/lib/internal/process/report.js index 87fad4c1958e5a..50ddc8c4b379a5 100644 --- a/lib/internal/process/report.js +++ b/lib/internal/process/report.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) { diff --git a/src/node_report_module.cc b/src/node_report_module.cc index f56da94bac196d..0e3f8981b71aac 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -48,12 +48,11 @@ void TriggerReport(const FunctionCallbackInfo& info) { std::string filename; Local stackstr; - if (info.Length() == 1) { - stackstr = info[0].As(); - } else { + CHECK_EQ(info.Length(), 2); + stackstr = info[1].As(); + + if (info[0]->IsString()) filename = *String::Utf8Value(isolate, info[0]); - stackstr = info[1].As(); - } filename = TriggerNodeReport( isolate, env, "JavaScript API", __func__, filename, stackstr); diff --git a/test/node-report/test-api-pass-error.js b/test/node-report/test-api-pass-error.js index 13e92570a72ead..9bf59ec425c3a8 100644 --- a/test/node-report/test-api-pass-error.js +++ b/test/node-report/test-api-pass-error.js @@ -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');