Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 34821f6

Browse filesBrowse files
Benjamin GruenbaumFishrock123
authored andcommitted
repl: don't terminate on null thrown
Previous behavior was to assume an error is a proper error in the repl module. A check was added to not terminate the process on thrown repl errors that are `null` or `undefined`. PR-URL: #14306 Fixes: #12373 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com
1 parent 53ad91c commit 34821f6
Copy full SHA for 34821f6

File tree

Expand file treeCollapse file tree

2 files changed

+32
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-2
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,23 @@ function REPLServer(prompt,
282282
self._domain.on('error', function debugDomainError(e) {
283283
debug('domain error');
284284
const top = replMap.get(self);
285+
285286
internalUtil.decorateErrorStack(e);
287+
const isError = internalUtil.isError(e);
286288
if (e instanceof SyntaxError && e.stack) {
287289
// remove repl:line-number and stack trace
288290
e.stack = e.stack
289291
.replace(/^repl:\d+\r?\n/, '')
290292
.replace(/^\s+at\s.*\n?/gm, '');
291-
} else if (e.stack && self.replMode === exports.REPL_MODE_STRICT) {
293+
} else if (isError && self.replMode === exports.REPL_MODE_STRICT) {
292294
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
293295
(_, pre, line) => pre + (line - 1));
294296
}
295-
top.outputStream.write((e.stack || e) + '\n');
297+
if (isError && e.stack) {
298+
top.outputStream.write(`${e.stack}\n`);
299+
} else {
300+
top.outputStream.write(`Thrown: ${String(e)}\n`);
301+
}
296302
top.bufferedCommand = '';
297303
top.lines.level = [];
298304
top.displayPrompt();
Collapse file
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
require('../common');
3+
const repl = require('repl');
4+
const assert = require('assert');
5+
const Stream = require('stream');
6+
7+
const output = new Stream();
8+
let text = '';
9+
output.write = output.pause = output.resume = function(buf) {
10+
text += buf.toString();
11+
};
12+
13+
const replserver = repl.start({
14+
output: output,
15+
input: process.stdin
16+
});
17+
18+
replserver.emit('line', 'process.nextTick(() => { throw null; })');
19+
replserver.emit('line', '.exit');
20+
21+
setTimeout(() => {
22+
console.log(text);
23+
assert(text.includes('Thrown: null'));
24+
}, 0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.