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
Prev Previous commit
Next Next commit
Remove stack trace for syntax error
  • Loading branch information
princejwesley committed Jul 15, 2016
commit b1dd10df9ff0a3bfa8b93e70dcf99e751e20e4be
13 changes: 6 additions & 7 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,16 +350,15 @@ function REPLServer(prompt,
debug('domain error');
const top = replMap.get(self);
internalUtil.decorateErrorStack(e);
if (e.stack && self.replMode === exports.REPL_MODE_STRICT) {
if (e instanceof SyntaxError && e.stack) {
// remove repl:line-number and stack trace
e.stack = e.stack
.replace(/^repl:\d+\r?\n/, '')
.replace(/^\s+at\s.*\n?/gm, '');
} else if (e.stack && self.replMode === exports.REPL_MODE_STRICT) {
e.stack = e.stack.replace(/(\s+at\s+repl:)(\d+)/,
(_, pre, line) => pre + (line - 1));
}
if (e instanceof SyntaxError &&
e.stack &&
!e.stack.match(/^SyntaxError:/)) {
// remove filename:line-number
e.stack = e.stack.replace(/^.*?\n/, '');
}
top.outputStream.write((e.stack || e) + '\n');
top.lineParser.reset();
top.bufferedCommand = '';
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,12 @@ function error_test() {
expect: "'node'\n" + prompt_unix },
{ client: client_unix, send: 'function name(){ return "nodejs"; };name()',
expect: "'nodejs'\n" + prompt_unix },
// Avoid emitting filename:line-number for SyntaxError
// Avoid emitting repl:line-number for SyntaxError
{ client: client_unix, send: 'a = 3.5e',
expect: /^(?!repl)/ },
// Avoid emitting stack trace
{ client: client_unix, send: 'a = 3.5e',
expect: /^(?!\s+at\s)/ },
]);
}

Expand Down