UNPKG

verror-0

Version:

VError without dependencies on top of nodejs standart library

30 lines (29 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiError = void 0; const is_error_js_1 = require("./is-error.js"); const verror_js_1 = require("./verror.js"); /* * Represents a collection of errors for the purpose of consumers that generally * only deal with one error. Callers can extract the individual errors * contained in this object, but may also just treat it as a normal single * error, in which case a summary message will be printed. */ class MultiError extends verror_js_1.VError { ase_errors; constructor(errors) { if (errors.some((e) => !(0, is_error_js_1.isError)(e))) { throw new Error('errors must be an Error list'); } let name = 'MultiError'; if (errors[0] && typeof errors[0] === 'object' && 'name' in errors[0]) { name = errors[0].name; } super({ cause: errors[0], name }, 'first of %d error%s', errors.length, errors.length === 1 ? '' : 's'); this.ase_errors = errors; } errors() { return this.ase_errors.slice(0); } } exports.MultiError = MultiError;