mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Change how error messages are shown
Instead of throwing the syntax errors with their source file location and needing to then catch them and call a `prettyErrorMessage` function in order to get the formatted error message, now syntax errors know how to pretty-print themselves (their `toString` method gets overridden). An intermediate `catch` & re-`throw` is needed at the level of `CoffeeScript.compile` and friends. But the benefit of this approach is that now libraries that use the `CoffeeScript` object directly don't need to bother catching the possible compilation errors and calling a special function in order to get the nice error messages; they can just print the error itself (or let it bubble up) and the error will know how to pretty-print itself.
This commit is contained in:
@@ -150,7 +150,7 @@
|
||||
};
|
||||
|
||||
compileScript = function(file, input, base) {
|
||||
var compiled, err, message, o, options, t, task, useColors;
|
||||
var compiled, err, message, o, options, t, task;
|
||||
if (base == null) {
|
||||
base = null;
|
||||
}
|
||||
@@ -195,8 +195,7 @@
|
||||
if (CoffeeScript.listeners('failure').length) {
|
||||
return;
|
||||
}
|
||||
useColors = process.stdout.isTTY && !process.env.NODE_DISABLE_COLORS;
|
||||
message = helpers.prettyErrorMessage(err, file || '[stdin]', input, useColors);
|
||||
message = err.stack || ("" + err);
|
||||
if (o.watch) {
|
||||
return printLine(message + '\x07');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user