Skip to content

Commit 9f446a1

Browse files
cjihrigBridgeAR
authored andcommitted
report: refactor configuration management
This commit removes process.report.setOptions(). Instead of using complex configuration synchronization between C++ and JS, this commit introduces individual getters and setters. PR-URL: #26414 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Wyatt Preul <[email protected]>
1 parent 01e69f9 commit 9f446a1

11 files changed

+390
-277
lines changed

Diff for: doc/api/process.md

+74-27
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,21 @@ added: v11.8.0
16691669
reports for the current process. Additional documentation is available in the
16701670
[report documentation][].
16711671

1672+
## process.report.directory
1673+
<!-- YAML
1674+
added: REPLACEME
1675+
-->
1676+
1677+
* {string}
1678+
1679+
Directory where the report is written. The default value is the empty string,
1680+
indicating that reports are written to the current working directory of the
1681+
Node.js process.
1682+
1683+
```js
1684+
console.log(`Report directory is ${process.report.directory}`);
1685+
```
1686+
16721687
### process.report.getReport([err])
16731688
<!-- YAML
16741689
added: v11.8.0
@@ -1687,43 +1702,75 @@ console.log(data);
16871702

16881703
Additional documentation is available in the [report documentation][].
16891704

1690-
### process.report.setOptions([options]);
1705+
## process.report.filename
16911706
<!-- YAML
1692-
added: v11.8.0
1707+
added: REPLACEME
16931708
-->
16941709

1695-
* `options` {Object}
1696-
* `events` {string[]}
1697-
* `signal`: Generate a report in response to a signal raised on the process.
1698-
* `exception`: Generate a report on unhandled exceptions.
1699-
* `fatalerror`: Generate a report on internal fault
1700-
(such as out of memory errors or native assertions).
1701-
* `signal` {string} Sets or resets the signal for report generation
1702-
(not supported on Windows). **Default:** `'SIGUSR2'`.
1703-
* `filename` {string} Name of the file where the report is written.
1704-
* `path` {string} Directory where the report is written.
1705-
**Default:** the current working directory of the Node.js process.
1710+
* {string}
17061711

1707-
Configures the diagnostic reporting behavior. Upon invocation, the runtime
1708-
is reconfigured to generate reports based on `options`. Several usage examples
1709-
are shown below.
1712+
Filename where the report is written. If set to the empty string, the output
1713+
filename will be comprised of a timestamp, PID, and sequence number. The default
1714+
value is the empty string.
17101715

17111716
```js
1712-
// Trigger a report on uncaught exceptions or fatal errors.
1713-
process.report.setOptions({ events: ['exception', 'fatalerror'] });
1717+
console.log(`Report filename is ${process.report.filename}`);
1718+
```
1719+
1720+
## process.report.reportOnFatalError
1721+
<!-- YAML
1722+
added: REPLACEME
1723+
-->
1724+
1725+
* {boolean}
17141726

1715-
// Change the default path and filename of the report.
1716-
process.report.setOptions({ filename: 'foo.json', path: '/home' });
1727+
If `true`, a diagnostic report is generated on fatal errors, such as out of
1728+
memory errors or failed C++ assertions.
17171729

1718-
// Produce the report onto stdout, when generated. Special meaning is attached
1719-
// to `stdout` and `stderr`. Usage of these will result in report being written
1720-
// to the associated standard streams. URLs are not supported.
1721-
process.report.setOptions({ filename: 'stdout' });
1730+
```js
1731+
console.log(`Report on fatal error: ${process.report.reportOnFatalError}`);
17221732
```
17231733

1724-
Signal based report generation is not supported on Windows.
1734+
## process.report.reportOnSignal
1735+
<!-- YAML
1736+
added: REPLACEME
1737+
-->
17251738

1726-
Additional documentation is available in the [report documentation][].
1739+
* {boolean}
1740+
1741+
If `true`, a diagnostic report is generated when the process receives the
1742+
signal specified by `process.report.signal`.
1743+
1744+
```js
1745+
console.log(`Report on signal: ${process.report.reportOnSignal}`);
1746+
```
1747+
1748+
## process.report.reportOnUncaughtException
1749+
<!-- YAML
1750+
added: REPLACEME
1751+
-->
1752+
1753+
* {boolean}
1754+
1755+
If `true`, a diagnostic report is generated on uncaught exception.
1756+
1757+
```js
1758+
console.log(`Report on exception: ${process.report.reportOnUncaughtException}`);
1759+
```
1760+
1761+
## process.report.signal
1762+
<!-- YAML
1763+
added: REPLACEME
1764+
-->
1765+
1766+
* {string}
1767+
1768+
The signal used to trigger the creation of a diagnostic report. Defaults to
1769+
`SIGUSR2`.
1770+
1771+
```js
1772+
console.log(`Report signal: ${process.report.signal}`);
1773+
```
17271774

17281775
### process.report.triggerReport([filename][, err])
17291776
<!-- YAML
@@ -1732,7 +1779,7 @@ added: v11.8.0
17321779

17331780
* `filename` {string} Name of the file where the report is written. This
17341781
should be a relative path, that will be appended to the directory specified in
1735-
`process.report.setOptions`, or the current working directory of the Node.js
1782+
`process.report.directory`, or the current working directory of the Node.js
17361783
process, if unspecified.
17371784
* `err` {Error} A custom error used for reporting the JavaScript stack.
17381785

Diff for: doc/api/report.md

+21-19
Original file line numberDiff line numberDiff line change
@@ -484,21 +484,17 @@ times for the same Node.js process.
484484

485485
## Configuration
486486

487-
Additional runtime configuration that influences the report generation
488-
constraints are available using `setOptions()` API.
487+
Additional runtime configuration of report generation is available via
488+
the following properties of `process.report`:
489489

490-
```js
491-
process.report.setOptions({
492-
events: ['exception', 'fatalerror', 'signal'],
493-
signal: 'SIGUSR2',
494-
filename: 'myreport.json',
495-
path: '/home/nodeuser'
496-
});
497-
```
490+
`reportOnFatalError` triggers diagnostic reporting on fatal errors when `true`.
491+
Defaults to `false`.
492+
493+
`reportOnSignal` triggers diagnostic reporting on signal when `true`. This is
494+
not supported on Windows. Defaults to `false`.
498495

499-
The `events` array contains one or more of the report triggering options.
500-
The only valid entries are `'exception'`, `'fatalerror'` and `'signal'`.
501-
By default, a report is not produced on any of these events.
496+
`reportOnUncaughtException` triggers diagnostic reporting on uncaught exception
497+
when `true`. Defaults to `false`.
502498

503499
`signal` specifies the POSIX signal identifier that will be used
504500
to intercept external triggers for report generation. Defaults to
@@ -507,24 +503,30 @@ to intercept external triggers for report generation. Defaults to
507503
`filename` specifies the name of the output file in the file system.
508504
Special meaning is attached to `stdout` and `stderr`. Usage of these
509505
will result in report being written to the associated standard streams.
510-
In such cases when standard streams are used, value in `'path'` is ignored.
506+
In cases where standard streams are used, the value in `'directory'` is ignored.
511507
URLs are not supported. Defaults to a composite filename that contains
512508
timestamp, PID and sequence number.
513509

514-
`path` specifies the filesystem directory where the report will be written to.
510+
`directory` specifies the filesystem directory where the report will be written.
515511
URLs are not supported. Defaults to the current working directory of the
516512
Node.js process.
517513

518514
```js
519515
// Trigger report only on uncaught exceptions.
520-
process.report.setOptions({ events: ['exception'] });
516+
process.report.reportOnFatalError = false;
517+
process.report.reportOnSignal = false;
518+
process.report.reportOnUncaughtException = true;
521519

522520
// Trigger report for both internal errors as well as external signal.
523-
process.report.setOptions({ events: ['fatalerror', 'signal'] });
521+
process.report.reportOnFatalError = true;
522+
process.report.reportOnSignal = true;
523+
process.report.reportOnUncaughtException = false;
524524

525525
// Change the default signal to `SIGQUIT` and enable it.
526-
process.report.setOptions(
527-
{ events: ['signal'], signal: 'SIGQUIT' });
526+
process.report.reportOnFatalError = false;
527+
process.report.reportOnUncaughtException = false;
528+
process.report.reportOnSignal = true;
529+
process.report.signal = 'SIGQUIT';
528530
```
529531

530532
Configuration on module initialization is also available via

Diff for: lib/internal/bootstrap/pre_execution.js

+5-14
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ function initializeReport() {
3939
if (!getOptionValue('--experimental-report')) {
4040
return;
4141
}
42-
const {
43-
config,
44-
report,
45-
syncConfig
46-
} = require('internal/process/report');
42+
const { report } = require('internal/process/report');
4743
process.report = report;
48-
// Download the CLI / ENV config into JS land.
49-
syncConfig(config, false);
5044
}
5145

5246
function setupSignalHandlers() {
@@ -67,13 +61,10 @@ function initializeReportSignalHandlers() {
6761
if (!getOptionValue('--experimental-report')) {
6862
return;
6963
}
70-
const {
71-
config,
72-
handleSignal
73-
} = require('internal/process/report');
74-
if (config.events.includes('signal')) {
75-
process.on(config.signal, handleSignal);
76-
}
64+
65+
const { addSignalHandler } = require('internal/process/report');
66+
67+
addSignalHandler();
7768
}
7869

7970
function setupTraceCategoryState() {

Diff for: lib/internal/process/execution.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,11 @@ function createFatalException() {
109109
if (er == null || er.domain == null) {
110110
try {
111111
const report = internalBinding('report');
112-
if (report != null &&
113-
require('internal/options')
114-
.getOptionValue('--experimental-report')) {
115-
const config = {};
116-
report.syncConfig(config, false);
117-
if (Array.isArray(config.events) &&
118-
config.events.includes('exception')) {
119-
report.triggerReport(er ? er.message : 'Exception',
120-
'Exception',
121-
null,
122-
er ? er.stack : undefined);
123-
}
112+
if (report != null && report.shouldReportOnUncaughtException()) {
113+
report.triggerReport(er ? er.message : 'Exception',
114+
'Exception',
115+
null,
116+
er ? er.stack : undefined);
124117
}
125118
} catch {} // Ignore the exception. Diagnostic reporting is unavailable.
126119
}

0 commit comments

Comments
 (0)