From b1dd10df9ff0a3bfa8b93e70dcf99e751e20e4be Mon Sep 17 00:00:00 2001 From: Prince J Wesley Date: Fri, 8 Jul 2016 19:16:34 +0530 Subject: [PATCH] Remove stack trace for syntax error --- lib/repl.js | 13 ++++++------- test/parallel/test-repl.js | 5 ++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/repl.js b/lib/repl.js index 8a60813c076675..75c0f301153588 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -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 = ''; diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index dfbf90ecba3f4d..9b54366d1905a6 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -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)/ }, ]); }