diff options
author | Christopher Hiller <boneskull@boneskull.com> | 2019-07-10 13:27:44 -0700 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-07-20 11:10:23 +0200 |
commit | 35e3f1f449d39253afe6b7075194876541948e52 (patch) | |
tree | 58c490ba5034bcbf78042964974aa7e76035c6e1 /doc | |
parent | ebc3876754de3d3b0ddd33697a5e3f38e8c488e2 (diff) | |
download | android-node-v8-35e3f1f449d39253afe6b7075194876541948e52.tar.gz android-node-v8-35e3f1f449d39253afe6b7075194876541948e52.tar.bz2 android-node-v8-35e3f1f449d39253afe6b7075194876541948e52.zip |
report: modify getReport() to return an Object
It's likely that anyone using `process.report.getReport()` will be
processing the return value thereafter (e.g., filtering fields or
redacting secrets). This change eliminates boilerplate by calling
`JSON.parse()` on the return value.
Also modified the `validateContent()` and `validate()` test helpers in
`test/common/report.js` to be somewhat more obvious and helpful. Of
note, a report failing validation will now be easier (though still not
_easy_) to read when prepended to the stack trace.
- Refs: https://github.com/nodejs/diagnostics/issues/315
PR-URL: https://github.com/nodejs/node/pull/28630
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/api/process.md | 13 | ||||
-rw-r--r-- | doc/api/report.md | 11 |
2 files changed, 16 insertions, 8 deletions
diff --git a/doc/api/process.md b/doc/api/process.md index 9bf2b7dc23..c5833e5bf4 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1726,14 +1726,19 @@ added: v11.8.0 --> * `err` {Error} A custom error used for reporting the JavaScript stack. -* Returns: {string} +* Returns: {Object} -Returns a JSON-formatted diagnostic report for the running process. The report's -JavaScript stack trace is taken from `err`, if present. +Returns a JavaScript Object representation of a diagnostic report for the +running process. The report's JavaScript stack trace is taken from `err`, if +present. ```js const data = process.report.getReport(); -console.log(data); +console.log(data.header.nodeJsVersion); + +// Similar to process.report.writeReport() +const fs = require('fs'); +fs.writeFileSync(util.inspect(data), 'my-report.log', 'utf8'); ``` Additional documentation is available in the [report documentation][]. diff --git a/doc/api/report.md b/doc/api/report.md index 268caf6416..08a0f602ab 100644 --- a/doc/api/report.md +++ b/doc/api/report.md @@ -463,12 +463,15 @@ try { // Any other code ``` -The content of the diagnostic report can be returned as a JSON-compatible object +The content of the diagnostic report can be returned as a JavaScript Object via an API call from a JavaScript application: ```js const report = process.report.getReport(); -console.log(report); +console.log(typeof report === 'object'); // true + +// Similar to process.report.writeReport() output +console.log(JSON.stringify(report, null, 2)); ``` This function takes an optional additional argument `err` - an `Error` object @@ -476,7 +479,7 @@ that will be used as the context for the JavaScript stack printed in the report. ```js const report = process.report.getReport(new Error('custom error')); -console.log(report); +console.log(typeof report === 'object'); // true ``` The API versions are useful when inspecting the runtime state from within @@ -498,7 +501,7 @@ Node.js report completed > ``` -When a report is triggered, start and end messages are issued to stderr +When a report is written, start and end messages are issued to stderr and the filename of the report is returned to the caller. The default filename includes the date, time, PID and a sequence number. The sequence number helps in associating the report dump with the runtime state if generated multiple |