verror-0
Version:
VError without dependencies on top of nodejs standart library
32 lines (31 loc) • 1.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WError = void 0;
const parse_args_js_1 = require("./parse-args.js");
const verror_js_1 = require("./verror.js");
/*
* Like JavaScript's built-in Error class, but supports a "cause" argument which
* is wrapped, not "folded in" as with VError. Accepts a printf-style message.
* The cause argument can be null.
*/
class WError extends verror_js_1.VError {
constructor(...args) {
const parsed = (0, parse_args_js_1.parseArgs)({
argv: args
});
const options = parsed.options;
options.skipCauseMessage = true;
options.name = options.name ?? 'WError';
super(options, '%s', parsed.shortmessage);
}
toString() {
let str = (this.hasOwnProperty('name') && this.name) || this.constructor.name || this.constructor.prototype.name;
if (this.message)
str += ': ' + this.message;
if ('jse_cause' in this && this.jse_cause && this.jse_cause.message) {
str += '; caused by ' + this.jse_cause.toString();
}
return str;
}
}
exports.WError = WError;