Skip to content

Commit

Permalink
report: rename triggerReport() to writeReport()
Browse files Browse the repository at this point in the history
writeReport() is more descriptive of what the function does.

PR-URL: #26527
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
cjihrig authored and BridgeAR committed Mar 14, 2019
1 parent 0f8d8d6 commit 74ab1aa
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
4 changes: 2 additions & 2 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ The signal used to trigger the creation of a diagnostic report. Defaults to
console.log(`Report signal: ${process.report.signal}`);
```

### process.report.triggerReport([filename][, err])
### process.report.writeReport([filename][, err])
<!-- YAML
added: v11.8.0
-->
Expand All @@ -1790,7 +1790,7 @@ filename includes the date, time, PID, and a sequence number. The report's
JavaScript stack trace is taken from `err`, if present.

```js
process.report.triggerReport();
process.report.writeReport();
```

Additional documentation is available in the [report documentation][].
Expand Down
12 changes: 6 additions & 6 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,14 @@ written.
A report can also be triggered via an API call from a JavaScript application:

```js
process.report.triggerReport();
process.report.writeReport();
```

This function takes an optional additional argument `filename`, which is
the name of a file into which the report is written.

```js
process.report.triggerReport('./foo.json');
process.report.writeReport('./foo.json');
```

This function takes an optional additional argument `err` - an `Error` object
Expand All @@ -424,19 +424,19 @@ as where it was handled.
try {
process.chdir('/non-existent-path');
} catch (err) {
process.report.triggerReport(err);
process.report.writeReport(err);
}
// Any other code
```

If both filename and error object are passed to `triggerReport()` the
If both filename and error object are passed to `writeReport()` the
error object must be the second parameter.

```js
try {
process.chdir('/non-existent-path');
} catch (err) {
process.report.triggerReport(filename, err);
process.report.writeReport(filename, err);
}
// Any other code
```
Expand Down Expand Up @@ -470,7 +470,7 @@ triggered using the Node.js REPL:

```raw
$ node
> process.report.triggerReport();
> process.report.writeReport();
Writing Node.js report to file: report.20181126.091102.8480.001.json
Node.js report completed
>
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ function createFatalException() {
try {
const report = internalBinding('report');
if (report != null && report.shouldReportOnUncaughtException()) {
report.triggerReport(er ? er.message : 'Exception',
'Exception',
null,
er ? er.stack : undefined);
report.writeReport(er ? er.message : 'Exception',
'Exception',
null,
er ? er.stack : undefined);
}
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
}
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/process/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
const { validateString } = require('internal/validators');
const nr = internalBinding('report');
const report = {
triggerReport(file, err) {
writeReport(file, err) {
if (typeof file === 'object' && file !== null) {
err = file;
file = undefined;
Expand All @@ -19,7 +19,7 @@ const report = {
throw new ERR_INVALID_ARG_TYPE('err', 'Object', err);
}

return nr.triggerReport('JavaScript API', 'API', file, err.stack);
return nr.writeReport('JavaScript API', 'API', file, err.stack);
},
getReport(err) {
if (err === undefined)
Expand Down Expand Up @@ -101,7 +101,7 @@ function removeSignalHandler() {
}

function signalHandler(sig) {
nr.triggerReport(sig, 'Signal', null, '');
nr.writeReport(sig, 'Signal', null, '');
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion src/node_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ std::string ValueToHexString(T value) {
}

// Function declarations - export functions in src/node_report_module.cc
void TriggerReport(const v8::FunctionCallbackInfo<v8::Value>& info);
void WriteReport(const v8::FunctionCallbackInfo<v8::Value>& info);
void GetReport(const v8::FunctionCallbackInfo<v8::Value>& info);

// Node.js boot time - defined in src/node.cc
Expand Down
5 changes: 2 additions & 3 deletions src/node_report_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ using v8::Object;
using v8::String;
using v8::Value;

// External JavaScript API for triggering a report
void TriggerReport(const FunctionCallbackInfo<Value>& info) {
void WriteReport(const FunctionCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
Isolate* isolate = env->isolate();
HandleScope scope(isolate);
Expand Down Expand Up @@ -161,7 +160,7 @@ static void Initialize(Local<Object> exports,
Local<Context> context) {
Environment* env = Environment::GetCurrent(context);

env->SetMethod(exports, "triggerReport", TriggerReport);
env->SetMethod(exports, "writeReport", WriteReport);
env->SetMethod(exports, "getReport", GetReport);
env->SetMethod(exports, "getDirectory", GetDirectory);
env->SetMethod(exports, "setDirectory", SetDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ function validate() {

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

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

{
// Test with a file argument.
const file = process.report.triggerReport('custom-name-1.json');
const file = process.report.writeReport('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');
Expand All @@ -49,8 +49,8 @@ function validate() {

{
// Test with file and error arguments.
const file = process.report.triggerReport('custom-name-2.json',
new Error('test error'));
const file = process.report.writeReport('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');
Expand All @@ -61,7 +61,7 @@ function validate() {
{
// Test with a filename option.
process.report.filename = 'custom-name-3.json';
const file = process.report.triggerReport();
const file = process.report.writeReport();
assert.strictEqual(helper.findReports(process.pid, tmpdir.path).length, 0);
const filename = path.join(process.report.directory, 'custom-name-3.json');
assert.strictEqual(file, process.report.filename);
Expand All @@ -72,21 +72,21 @@ function validate() {
// Test with an invalid file argument.
[null, 1, Symbol(), function() {}].forEach((file) => {
common.expectsError(() => {
process.report.triggerReport(file);
process.report.writeReport(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);
process.report.writeReport('file', error);
}, { code: 'ERR_INVALID_ARG_TYPE' });
});

{
// Test the special "stdout" filename.
const args = ['--experimental-report', '-e',
'process.report.triggerReport("stdout")'];
'process.report.writeReport("stdout")'];
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
Expand All @@ -97,7 +97,7 @@ function validate() {
{
// Test the special "stderr" filename.
const args = ['--experimental-report', '-e',
'process.report.triggerReport("stderr")'];
'process.report.writeReport("stderr")'];
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
assert.strictEqual(child.status, 0);
assert.strictEqual(child.signal, null);
Expand All @@ -113,7 +113,7 @@ function validate() {
const args = ['--experimental-report',
`--diagnostic-report-directory=${reportDir}`,
'-e',
'process.report.triggerReport()'];
'process.report.writeReport()'];
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });

assert.strictEqual(child.status, 0);
Expand Down

0 comments on commit 74ab1aa

Please sign in to comment.