From 09cc5b2114bb956d74bb94337d817e3e30fe7f0c Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 8 Mar 2019 11:59:08 -0500 Subject: [PATCH] report: rename triggerReport() to writeReport() writeReport() is more descriptive of what the function does. PR-URL: https://github.com/nodejs/node/pull/26527 Reviewed-By: Richard Lau Reviewed-By: Ruben Bridgewater --- doc/api/process.md | 4 ++-- doc/api/report.md | 12 +++++----- lib/internal/process/execution.js | 8 +++---- lib/internal/process/report.js | 6 ++--- src/node_report.h | 2 +- src/node_report_module.cc | 5 ++--- ...erreport.js => test-report-writereport.js} | 22 +++++++++---------- 7 files changed, 29 insertions(+), 30 deletions(-) rename test/report/{test-report-triggerreport.js => test-report-writereport.js} (86%) diff --git a/doc/api/process.md b/doc/api/process.md index b8d34f264d63ec..6d96e9033827f7 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -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]) @@ -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][]. diff --git a/doc/api/report.md b/doc/api/report.md index c371775eabe8cd..7cb349395314e2 100644 --- a/doc/api/report.md +++ b/doc/api/report.md @@ -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 @@ -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 ``` @@ -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 > diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index 310acc14b4aa66..7118dbf3ad50d2 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -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. } diff --git a/lib/internal/process/report.js b/lib/internal/process/report.js index c96443102534ba..ff4e72f54c9978 100644 --- a/lib/internal/process/report.js +++ b/lib/internal/process/report.js @@ -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; @@ -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) @@ -101,7 +101,7 @@ function removeSignalHandler() { } function signalHandler(sig) { - nr.triggerReport(sig, 'Signal', null, ''); + nr.writeReport(sig, 'Signal', null, ''); } module.exports = { diff --git a/src/node_report.h b/src/node_report.h index 7aff7a5e2fa60b..18135f5666c68a 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -67,7 +67,7 @@ std::string ValueToHexString(T value) { } // Function declarations - export functions in src/node_report_module.cc -void TriggerReport(const v8::FunctionCallbackInfo& info); +void WriteReport(const v8::FunctionCallbackInfo& info); void GetReport(const v8::FunctionCallbackInfo& info); // Node.js boot time - defined in src/node.cc diff --git a/src/node_report_module.cc b/src/node_report_module.cc index 202730d3b68d4a..94894b0f5e5f9c 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -30,8 +30,7 @@ using v8::Object; using v8::String; using v8::Value; -// External JavaScript API for triggering a report -void TriggerReport(const FunctionCallbackInfo& info) { +void WriteReport(const FunctionCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); Isolate* isolate = env->isolate(); HandleScope scope(isolate); @@ -161,7 +160,7 @@ static void Initialize(Local exports, Local 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); diff --git a/test/report/test-report-triggerreport.js b/test/report/test-report-writereport.js similarity index 86% rename from test/report/test-report-triggerreport.js rename to test/report/test-report-writereport.js index c89959ae8754f7..6c7ed8a71c8457 100644 --- a/test/report/test-report-triggerreport.js +++ b/test/report/test-report-writereport.js @@ -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'); @@ -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'); @@ -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); @@ -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); @@ -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); @@ -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);