only output code frame and message on syntax errors in CLI - fixes #1971

This commit is contained in:
Sebastian McKenzie 2015-07-31 02:19:06 +01:00
parent 547aaac0c0
commit f5d9427153

View File

@ -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);
});