diff --git a/lib/repl.js b/lib/repl.js index a06ca0dd990f29..e6af28688bb896 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -772,6 +772,10 @@ function REPLServer(prompt, const ln = lines.length === 1 ? ' ' : ':\n'; errStack = `Uncaught${ln}${errStack}`; } + // If colors are allowed, print in red + if (self.useColors) { + errStack = '\u001b[31m' + errStack + '\u001b[39m'; + } // Normalize line endings. errStack += StringPrototypeEndsWith(errStack, '\n') ? '' : '\n'; self.output.write(errStack); diff --git a/test/parallel/test-repl-pretty-stack.js b/test/parallel/test-repl-pretty-stack.js index 2aad0e09b6d9ba..ab616bdaff964b 100644 --- a/test/parallel/test-repl-pretty-stack.js +++ b/test/parallel/test-repl-pretty-stack.js @@ -64,8 +64,8 @@ const tests = [ { command: '(() => { const err = Error(\'Whoops!\'); ' + 'err.foo = \'bar\'; throw err; })()', - expected: 'Uncaught Error: Whoops!\n at REPL5:*:* {\n foo: ' + - "\u001b[32m'bar'\u001b[39m\n}\n", + expected: '\x1B[31mUncaught Error: Whoops!\n at REPL5:*:* {\n foo: ' + + "\u001b[32m'bar'\u001b[39m\n}\x1B[31m\n", useColors: true }, { diff --git a/test/parallel/test-repl-uncaught-exception.js b/test/parallel/test-repl-uncaught-exception.js index d3dbe0acb0106d..233840f371c6cf 100644 --- a/test/parallel/test-repl-uncaught-exception.js +++ b/test/parallel/test-repl-uncaught-exception.js @@ -40,12 +40,12 @@ const tests = [ { useColors: true, command: 'x', - expected: 'Uncaught ReferenceError: x is not defined\n' + expected: '\x1B[31mUncaught ReferenceError: x is not defined\x1B[39m\n' }, { useColors: true, command: 'throw { foo: "test" }', - expected: "Uncaught { foo: \x1B[32m'test'\x1B[39m }\n" + expected: "\x1B[31mUncaught { foo: \x1B[32m'test'\x1B[39m }\x1B[39m\n" }, { command: 'process.on("uncaughtException", () => console.log("Foobar"));\n',