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: https://github.com/nodejs/node/pull/14306 Fixes: https://github.com/nodejs/node/issues/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
This commit is contained in:
parent
0e5283b7ed
commit
030a0285d8
10
lib/repl.js
10
lib/repl.js
@ -283,17 +283,23 @@ function REPLServer(prompt,
|
|||||||
self._domain.on('error', function debugDomainError(e) {
|
self._domain.on('error', function debugDomainError(e) {
|
||||||
debug('domain error');
|
debug('domain error');
|
||||||
const top = replMap.get(self);
|
const top = replMap.get(self);
|
||||||
|
|
||||||
internalUtil.decorateErrorStack(e);
|
internalUtil.decorateErrorStack(e);
|
||||||
|
const isError = internalUtil.isError(e);
|
||||||
if (e instanceof SyntaxError && e.stack) {
|
if (e instanceof SyntaxError && e.stack) {
|
||||||
// remove repl:line-number and stack trace
|
// remove repl:line-number and stack trace
|
||||||
e.stack = e.stack
|
e.stack = e.stack
|
||||||
.replace(/^repl:\d+\r?\n/, '')
|
.replace(/^repl:\d+\r?\n/, '')
|
||||||
.replace(/^\s+at\s.*\n?/gm, '');
|
.replace(/^\s+at\s.*\n?/gm, '');
|
||||||
} else if (e.stack && self.replMode === exports.REPL_MODE_STRICT) {
|
} else if (isError && self.replMode === exports.REPL_MODE_STRICT) {
|
||||||
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
|
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
|
||||||
(_, pre, line) => pre + (line - 1));
|
(_, pre, line) => pre + (line - 1));
|
||||||
}
|
}
|
||||||
top.outputStream.write((e.stack || e) + '\n');
|
if (isError && e.stack) {
|
||||||
|
top.outputStream.write(`${e.stack}\n`);
|
||||||
|
} else {
|
||||||
|
top.outputStream.write(`Thrown: ${String(e)}\n`);
|
||||||
|
}
|
||||||
top.bufferedCommand = '';
|
top.bufferedCommand = '';
|
||||||
top.lines.level = [];
|
top.lines.level = [];
|
||||||
top.displayPrompt();
|
top.displayPrompt();
|
||||||
|
24
test/parallel/test-repl-null-thrown.js
Normal file
24
test/parallel/test-repl-null-thrown.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const repl = require('repl');
|
||||||
|
const assert = require('assert');
|
||||||
|
const Stream = require('stream');
|
||||||
|
|
||||||
|
const output = new Stream();
|
||||||
|
let text = '';
|
||||||
|
output.write = output.pause = output.resume = function(buf) {
|
||||||
|
text += buf.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
const replserver = repl.start({
|
||||||
|
output: output,
|
||||||
|
input: process.stdin
|
||||||
|
});
|
||||||
|
|
||||||
|
replserver.emit('line', 'process.nextTick(() => { throw null; })');
|
||||||
|
replserver.emit('line', '.exit');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log(text);
|
||||||
|
assert(text.includes('Thrown: null'));
|
||||||
|
}, 0);
|
Loading…
x
Reference in New Issue
Block a user