diff --git a/lib/repl.js b/lib/repl.js index 1f89f43c241488..9d878e843f1ff7 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -415,7 +415,7 @@ function REPLServer(prompt, (_, pre, line) => pre + (line - 1)); } } - errStack = util.inspect(e); + errStack = self.writer(e); // Remove one line error braces to keep the old style in place. if (errStack[errStack.length - 1] === ']') { @@ -425,7 +425,7 @@ function REPLServer(prompt, } if (errStack === '') { - errStack = `Thrown: ${util.inspect(e)}\n`; + errStack = `Thrown: ${self.writer(e)}\n`; } else { const ln = errStack.endsWith('\n') ? '' : '\n'; errStack = `Thrown:\n${errStack}${ln}`; diff --git a/test/parallel/test-repl-pretty-stack.js b/test/parallel/test-repl-pretty-stack.js index e4137b84a4c2b5..4bf18fa1c2da92 100644 --- a/test/parallel/test-repl-pretty-stack.js +++ b/test/parallel/test-repl-pretty-stack.js @@ -6,7 +6,7 @@ const assert = require('assert'); const repl = require('repl'); -function run({ command, expected }) { +function run({ command, expected, ...extraREPLOptions }) { let accum = ''; const inputStream = new ArrayStream(); @@ -19,7 +19,8 @@ function run({ command, expected }) { input: inputStream, output: outputStream, terminal: false, - useColors: false + useColors: false, + ...extraREPLOptions }); r.write(`${command}\n`); @@ -44,6 +45,18 @@ const tests = [ command: 'throw new Error(\'Whoops!\')', expected: 'Thrown:\nError: Whoops!\n' }, + { + command: '(() => { const err = Error(\'Whoops!\'); ' + + 'err.foo = \'bar\'; throw err; })()', + expected: 'Thrown:\n{ Error: Whoops!\n at repl:1:22 foo: \'bar\' }\n', + }, + { + command: '(() => { const err = Error(\'Whoops!\'); ' + + 'err.foo = \'bar\'; throw err; })()', + expected: 'Thrown:\n{ Error: Whoops!\n at repl:1:22 foo: ' + + "\u001b[32m'bar'\u001b[39m }\n", + useColors: true + }, { command: 'foo = bar;', expected: 'Thrown:\nReferenceError: bar is not defined\n'