improve error messages (#1506)

- better inheritance of `Error` sub-classes
- mark parse error against source in CLI

closes #235
closes #348
closes #524
closes #1356
closes #1405
This commit is contained in:
Alex Lam S.L
2017-02-27 03:40:54 +08:00
committed by GitHub
parent b1c593a041
commit 872270b149
15 changed files with 133 additions and 48 deletions

View File

@@ -78,13 +78,28 @@ function repeat_string(str, i) {
return d;
};
function configure_error_stack(fn) {
Object.defineProperty(fn.prototype, "stack", {
get: function() {
var err = new Error(this.message);
err.name = this.name;
try {
throw err;
} catch(e) {
return e.stack;
}
}
});
}
function DefaultsError(msg, defs) {
Error.call(this, msg);
this.msg = msg;
this.message = msg;
this.defs = defs;
};
DefaultsError.prototype = Object.create(Error.prototype);
DefaultsError.prototype.constructor = DefaultsError;
DefaultsError.prototype.name = "DefaultsError";
configure_error_stack(DefaultsError);
DefaultsError.croak = function(msg, defs) {
throw new DefaultsError(msg, defs);