GeezerVison is showing github.com — lib: honor setUncaughtExceptionCaptureCallback · nodejs/node@d58a466
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/process/execution.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -92,12 +92,16 @@ function evalScript(name, body, breakFirstLine, print) { |
92 | 92 | globalThis.module = origModule; |
93 | 93 | } |
94 | 94 |
|
95 | | -const exceptionHandlerState = { captureFn: null }; |
| 95 | +const exceptionHandlerState = { |
| 96 | + captureFn: null, |
| 97 | + reportFlag: false |
| 98 | +}; |
96 | 99 |
|
97 | 100 | function setUncaughtExceptionCaptureCallback(fn) { |
98 | 101 | if (fn === null) { |
99 | 102 | exceptionHandlerState.captureFn = fn; |
100 | 103 | shouldAbortOnUncaughtToggle[0] = 1; |
| 104 | + process.report.reportOnUncaughtException = exceptionHandlerState.reportFlag; |
101 | 105 | return; |
102 | 106 | } |
103 | 107 | if (typeof fn !== 'function') { |
@@ -108,6 +112,9 @@ function setUncaughtExceptionCaptureCallback(fn) { |
108 | 112 | } |
109 | 113 | exceptionHandlerState.captureFn = fn; |
110 | 114 | shouldAbortOnUncaughtToggle[0] = 0; |
| 115 | + exceptionHandlerState.reportFlag = |
| 116 | + process.report.reportOnUncaughtException === true; |
| 117 | + process.report.reportOnUncaughtException = false; |
111 | 118 | } |
112 | 119 |
|
113 | 120 | function hasUncaughtExceptionCaptureCallback() { |
|
Collapse file
Copy file name to clipboard +26Lines changed: 26 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Flags: --report-uncaught-exception |
| 2 | +'use strict'; |
| 3 | +// Test report is suppressed on uncaught exception hook. |
| 4 | +const common = require('../common'); |
| 5 | +const assert = require('assert'); |
| 6 | +const helper = require('../common/report'); |
| 7 | +const tmpdir = require('../common/tmpdir'); |
| 8 | +const error = new Error('test error'); |
| 9 | + |
| 10 | +tmpdir.refresh(); |
| 11 | +process.report.directory = tmpdir.path; |
| 12 | + |
| 13 | +// First, install an uncaught exception hook. |
| 14 | +process.setUncaughtExceptionCaptureCallback(common.mustCall()); |
| 15 | + |
| 16 | +// Make sure this is ignored due to the above override. |
| 17 | +process.on('uncaughtException', common.mustNotCall()); |
| 18 | + |
| 19 | +process.on('exit', (code) => { |
| 20 | + assert.strictEqual(code, 0); |
| 21 | + // Make sure no reports are generated. |
| 22 | + const reports = helper.findReports(process.pid, tmpdir.path); |
| 23 | + assert.strictEqual(reports.length, 0); |
| 24 | +}); |
| 25 | + |
| 26 | +throw error; |