diff options
Diffstat (limited to 'lib/repl.js')
-rw-r--r-- | lib/repl.js | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/repl.js b/lib/repl.js index c1473588d3..55daf2f47f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -552,11 +552,28 @@ function REPLServer(prompt, }); } else { if (errStack === '') { - errStack = `Thrown: ${self.writer(e)}\n`; - } else { - const ln = errStack.endsWith('\n') ? '' : '\n'; - errStack = `Thrown:\n${errStack}${ln}`; + errStack = self.writer(e); + } + const lines = errStack.split(/(?<=\n)/); + let matched = false; + + errStack = ''; + for (const line of lines) { + if (!matched && /^\[?([A-Z][a-z0-9_]*)*Error/.test(line)) { + errStack += writer.options.breakLength >= line.length ? + `Uncaught ${line}` : + `Uncaught:\n${line}`; + matched = true; + } else { + errStack += line; + } + } + if (!matched) { + const ln = lines.length === 1 ? ' ' : ':\n'; + errStack = `Uncaught${ln}${errStack}`; } + // Normalize line endings. + errStack += errStack.endsWith('\n') ? '' : '\n'; top.outputStream.write(errStack); top.clearBufferedCommand(); top.lines.level = []; |