Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions lib/internal/process/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions src/node_report_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
72 changes: 68 additions & 4 deletions test/node-report/test-api-nohooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
const common = require('../common');
common.skipIfReportDisabled();
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const helper = require('../common/report');
const tmpdir = require('../common/tmpdir');

Expand All @@ -13,7 +15,69 @@ common.expectWarning('ExperimentalWarning',
'change at any time');
tmpdir.refresh();
process.report.setOptions({ path: tmpdir.path });
process.report.triggerReport();
const reports = helper.findReports(process.pid, tmpdir.path);
assert.strictEqual(reports.length, 1);
helper.validate(reports[0]);

function validate() {
const reports = helper.findReports(process.pid, tmpdir.path);
assert.strictEqual(reports.length, 1);
helper.validate(reports[0]);
fs.unlinkSync(reports[0]);
return reports[0];
}

{
// Test with no arguments.
process.report.triggerReport();
validate();
}

{
// Test with an error argument.
process.report.triggerReport(new Error('test error'));
validate();
}

{
// Test with a file argument.
const file = process.report.triggerReport('custom-name-1.json');
const absolutePath = path.join(tmpdir.path, file);
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
assert.strictEqual(file, 'custom-name-1.json');
helper.validate(absolutePath);
fs.unlinkSync(absolutePath);
}

{
// Test with file and error arguments.
const file = process.report.triggerReport('custom-name-2.json',
new Error('test error'));
const absolutePath = path.join(tmpdir.path, file);
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
assert.strictEqual(file, 'custom-name-2.json');
helper.validate(absolutePath);
fs.unlinkSync(absolutePath);
}

{
// Test with a filename option.
const filename = path.join(tmpdir.path, 'custom-name-3.json');
process.report.setOptions({ filename });
const file = process.report.triggerReport();
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
assert.strictEqual(file, filename);
helper.validate(filename);
fs.unlinkSync(filename);
}

// Test with an invalid file argument.
[null, 1, Symbol(), function() {}].forEach((file) => {
common.expectsError(() => {
process.report.triggerReport(file);
}, { code: 'ERR_INVALID_ARG_TYPE' });
});

// Test with an invalid error argument.
[null, 1, Symbol(), function() {}, 'foo'].forEach((error) => {
common.expectsError(() => {
process.report.triggerReport('file', error);
}, { code: 'ERR_INVALID_ARG_TYPE' });
});
30 changes: 0 additions & 30 deletions test/node-report/test-api-pass-error.js

This file was deleted.

29 changes: 0 additions & 29 deletions test/node-report/test-api-trigger-with-filename.js

This file was deleted.

30 changes: 0 additions & 30 deletions test/node-report/test-api-trigger-with-options.js

This file was deleted.