From 34821f6400e35478a87bacd78b830cb31e4db07c Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sun, 16 Jul 2017 18:12:57 +0300 Subject: [PATCH] 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 Reviewed-By: Timothy Gu Reviewed-By: Jeremiah Senkpiel Reviewed-By: Colin Ihrig 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.lines.level = []; top.displayPrompt(); diff --git a/test/parallel/test-repl-null-thrown.js b/test/parallel/test-repl-null-thrown.js new file mode 100644 index 00000000000000..1fe5d30396d534 --- /dev/null +++ b/test/parallel/test-repl-null-thrown.js @@ -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);