Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
repl: fix error message printing
The REPL implementation would strip away the first and last character
of a formatted error message if it ended with `]` (but with the
obviously missing check for a starting `]`), leading to things like
`Uncaught rror: foo[a` being printed for input like `Error: foo[a]`.

Refs: #22436
  • Loading branch information
addaleax committed Apr 12, 2021
commit a4824874fb8e3f3802ebd2f7bbf5885d18f0f7e6
2 changes: 1 addition & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,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 = StringPrototypeSlice(errStack, 1, -1);
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-repl-pretty-stack-custom-writer.js
Original file line number Diff line number Diff line change
@@ -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`);
Comment thread
addaleax marked this conversation as resolved.
Outdated
r.close();
assert.strictEqual(output.read().toString(), 'Uncaught Error: foo[a]\n');
}