From f5d94271537d3adf83862777c23e07a62a462ec1 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 31 Jul 2015 02:19:06 +0100 Subject: [PATCH] only output code frame and message on syntax errors in CLI - fixes #1971 --- packages/babel-cli/src/babel/util.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/babel-cli/src/babel/util.js b/packages/babel-cli/src/babel/util.js index 8ade28d1d6..f0ace28524 100644 --- a/packages/babel-cli/src/babel/util.js +++ b/packages/babel-cli/src/babel/util.js @@ -47,10 +47,23 @@ exports.compile = function (filename, opts) { return exports.transform(filename, code, opts); } catch (err) { if (commander.watch) { - console.error(err.stack); + console.error(toErrorStack(err)); return { ignored: true }; } else { throw err; } } }; + +function toErrorStack(err) { + if (err._babel && err instanceof SyntaxError) { + return err.message + "\n" + err.codeFrame; + } else { + return err.stack; + } +}; + +process.on("uncaughtException", function (err) { + console.error(toErrorStack(err)); + process.exit(1); +});