diff --git a/lib/repl.js b/lib/repl.js index 10ca72f0e79d26..365df8a1bcb6aa 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -566,7 +566,7 @@ function REPLServer(prompt, errStack = self.writer(e); // Remove one line error braces to keep the old style in place. - if (errStack[errStack.length - 1] === ']') { + if (errStack[0] === '[' && errStack[errStack.length - 1] === ']') { errStack = errStack.slice(1, -1); } } diff --git a/test/parallel/test-repl-pretty-stack-custom-writer.js b/test/parallel/test-repl-pretty-stack-custom-writer.js new file mode 100644 index 00000000000000..877f8cb8077597 --- /dev/null +++ b/test/parallel/test-repl-pretty-stack-custom-writer.js @@ -0,0 +1,23 @@ +'use strict'; +require('../common'); +const { PassThrough } = require('stream'); +const assert = require('assert'); +const repl = require('repl'); + +{ + const input = new PassThrough(); + const output = new PassThrough(); + + const r = repl.start({ + prompt: '', + input, + output, + writer: String, + terminal: false, + useColors: false + }); + + r.write('throw new Error("foo[a]")\n'); + r.close(); + assert.strictEqual(output.read().toString(), 'Uncaught Error: foo[a]\n'); +}