Skip to content

Commit

Permalink
Remove stack trace for syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
princejwesley committed Jul 15, 2016
1 parent 048cf6b commit b1dd10d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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

0 comments on commit b1dd10d

Please sign in to comment.