Skip to content

Commit ddff2b2

Browse files
committedOct 15, 2020
lib: honor setUncaughtExceptionCaptureCallback
This api does not alter the behavior of diagnostic report configured on uncaught exceptions. This is deemed as a bug. Honor this API. Refs: #35588 PR-URL: #35595 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 4079bfd commit ddff2b2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎lib/internal/process/execution.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,16 @@ function evalScript(name, body, breakFirstLine, print) {
9292
globalThis.module = origModule;
9393
}
9494

95-
const exceptionHandlerState = { captureFn: null };
95+
const exceptionHandlerState = {
96+
captureFn: null,
97+
reportFlag: false
98+
};
9699

97100
function setUncaughtExceptionCaptureCallback(fn) {
98101
if (fn === null) {
99102
exceptionHandlerState.captureFn = fn;
100103
shouldAbortOnUncaughtToggle[0] = 1;
104+
process.report.reportOnUncaughtException = exceptionHandlerState.reportFlag;
101105
return;
102106
}
103107
if (typeof fn !== 'function') {
@@ -108,6 +112,9 @@ function setUncaughtExceptionCaptureCallback(fn) {
108112
}
109113
exceptionHandlerState.captureFn = fn;
110114
shouldAbortOnUncaughtToggle[0] = 0;
115+
exceptionHandlerState.reportFlag =
116+
process.report.reportOnUncaughtException === true;
117+
process.report.reportOnUncaughtException = false;
111118
}
112119

113120
function hasUncaughtExceptionCaptureCallback() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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;

0 commit comments

Comments
 (0)