Skip to content

Commit

Permalink
lib: honor setUncaughtExceptionCaptureCallback
Browse files Browse the repository at this point in the history
This api does not alter the behavior of diagnostic
report configured on uncaught exceptions.
This is deemed as a bug. Honor this API.

Refs: nodejs#35588
PR-URL: nodejs#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>
  • Loading branch information
gireeshpunathil authored and joesepi committed Oct 22, 2020
1 parent c3d7064 commit 8716650
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/internal/process/execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ function evalScript(name, body, breakFirstLine, print) {
globalThis.module = origModule;
}

const exceptionHandlerState = { captureFn: null };
const exceptionHandlerState = {
captureFn: null,
reportFlag: false
};

function setUncaughtExceptionCaptureCallback(fn) {
if (fn === null) {
exceptionHandlerState.captureFn = fn;
shouldAbortOnUncaughtToggle[0] = 1;
process.report.reportOnUncaughtException = exceptionHandlerState.reportFlag;
return;
}
if (typeof fn !== 'function') {
Expand All @@ -108,6 +112,9 @@ function setUncaughtExceptionCaptureCallback(fn) {
}
exceptionHandlerState.captureFn = fn;
shouldAbortOnUncaughtToggle[0] = 0;
exceptionHandlerState.reportFlag =
process.report.reportOnUncaughtException === true;
process.report.reportOnUncaughtException = false;
}

function hasUncaughtExceptionCaptureCallback() {
Expand Down
26 changes: 26 additions & 0 deletions test/report/test-report-uncaught-exception-override.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Flags: --report-uncaught-exception
'use strict';
// Test report is suppressed on uncaught exception hook.
const common = require('../common');
const assert = require('assert');
const helper = require('../common/report');
const tmpdir = require('../common/tmpdir');
const error = new Error('test error');

tmpdir.refresh();
process.report.directory = tmpdir.path;

// First, install an uncaught exception hook.
process.setUncaughtExceptionCaptureCallback(common.mustCall());

// Make sure this is ignored due to the above override.
process.on('uncaughtException', common.mustNotCall());

process.on('exit', (code) => {
assert.strictEqual(code, 0);
// Make sure no reports are generated.
const reports = helper.findReports(process.pid, tmpdir.path);
assert.strictEqual(reports.length, 0);
});

throw error;

0 comments on commit 8716650

Please sign in to comment.