Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ function setupExceptionCapture() {

process.addUncaughtExceptionCaptureCallback((err) => {
const store = replContext.getStore();
if (store?.replServer && !store.replServer.closed) {
// TODO(addaleax): Add back a `store.replServer.closed` check here
// as a semver-major change.
// This check may need to allow for an opt-out, since the change in
// behavior could lead to DoS vulnerabilities (e.g. in the case of
// the net-based REPL described in our docs).
if (store?.replServer) {
store.replServer._handleError(err);
return true; // We handled it
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-repl-uncaught-exception-after-input-ended.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
const { start } = require('node:repl');
const { PassThrough } = require('node:stream');
const assert = require('node:assert');

// This test verifies that uncaught exceptions in the REPL
// do not bring down the process, even if stdin may already
// have been ended at that point (and the REPL closed as
// a result of that).
const input = new PassThrough();
const output = new PassThrough().setEncoding('utf8');
start({
input,
output,
terminal: false,
});

input.end('setImmediate(() => { throw new Error("test"); });\n');

setImmediate(common.mustCall(() => {
assert.match(output.read(), /Uncaught Error: test/);
}));
Loading