pax_global_header00006660000000000000000000000064135455561210014521gustar00rootroot0000000000000052 comment=58a3c04da70abd6e4795a0bc77dcd173dd86050a aggregate-error-3.0.1/000077500000000000000000000000001354555612100145775ustar00rootroot00000000000000aggregate-error-3.0.1/.editorconfig000066400000000000000000000002571354555612100172600ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 aggregate-error-3.0.1/.gitattributes000066400000000000000000000000231354555612100174650ustar00rootroot00000000000000* text=auto eol=lf aggregate-error-3.0.1/.github/000077500000000000000000000000001354555612100161375ustar00rootroot00000000000000aggregate-error-3.0.1/.github/funding.yml000066400000000000000000000001331354555612100203110ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus custom: https://sindresorhus.com/donate aggregate-error-3.0.1/.gitignore000066400000000000000000000000271354555612100165660ustar00rootroot00000000000000node_modules yarn.lock aggregate-error-3.0.1/.npmrc000066400000000000000000000000231354555612100157120ustar00rootroot00000000000000package-lock=false aggregate-error-3.0.1/.travis.yml000066400000000000000000000000651354555612100167110ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' aggregate-error-3.0.1/index.d.ts000066400000000000000000000034151354555612100165030ustar00rootroot00000000000000/** Create an error from multiple errors. */ declare class AggregateError extends Error implements Iterable { readonly name: 'AggregateError'; /** @param errors - If a string, a new `Error` is created with the string as the error message. If a non-Error object, a new `Error` is created with all properties from the object copied over. @returns An Error that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors. @example ``` import AggregateError = require('aggregate-error'); const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]); throw error; // AggregateError: // Error: foo // at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:33) // Error: bar // at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) // Error: baz // at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) // at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3) // at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) // at Module._compile (module.js:556:32) // at Object.Module._extensions..js (module.js:565:10) // at Module.load (module.js:473:32) // at tryModuleLoad (module.js:432:12) // at Function.Module._load (module.js:424:3) // at Module.runMain (module.js:590:10) // at run (bootstrap_node.js:394:7) // at startup (bootstrap_node.js:149:9) for (const individualError of error) { console.log(individualError); } //=> [Error: foo] //=> [Error: bar] //=> [Error: baz] ``` */ constructor(errors: ReadonlyArray); [Symbol.iterator](): IterableIterator; } export = AggregateError; aggregate-error-3.0.1/index.js000066400000000000000000000023441354555612100162470ustar00rootroot00000000000000'use strict'; const indentString = require('indent-string'); const cleanStack = require('clean-stack'); const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, ''); class AggregateError extends Error { constructor(errors) { if (!Array.isArray(errors)) { throw new TypeError(`Expected input to be an Array, got ${typeof errors}`); } errors = [...errors].map(error => { if (error instanceof Error) { return error; } if (error !== null && typeof error === 'object') { // Handle plain error objects with message property and/or possibly other metadata return Object.assign(new Error(error.message), error); } return new Error(error); }); let message = errors .map(error => { // The `stack` property is not standardized, so we can't assume it exists return typeof error.stack === 'string' ? cleanInternalStack(cleanStack(error.stack)) : String(error); }) .join('\n'); message = '\n' + indentString(message, 4); super(message); this.name = 'AggregateError'; Object.defineProperty(this, '_errors', {value: errors}); } * [Symbol.iterator]() { for (const error of this._errors) { yield error; } } } module.exports = AggregateError; aggregate-error-3.0.1/index.test-d.ts000066400000000000000000000005311354555612100174540ustar00rootroot00000000000000import {expectType} from 'tsd'; import AggregateError = require('.'); const aggregateError = new AggregateError([ new Error('foo'), {foo: 'bar'}, 'bar' ]); expectType>(aggregateError); expectType>(aggregateError[Symbol.iterator]()); for (const error of aggregateError) { expectType(error); } aggregate-error-3.0.1/license000066400000000000000000000021251354555612100161440ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. aggregate-error-3.0.1/package.json000066400000000000000000000012661354555612100170720ustar00rootroot00000000000000{ "name": "aggregate-error", "version": "3.0.1", "description": "Create an error from multiple errors", "license": "MIT", "repository": "sindresorhus/aggregate-error", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "aggregate", "error", "combine", "multiple", "many", "collection", "iterable", "iterator" ], "dependencies": { "clean-stack": "^2.0.0", "indent-string": "^4.0.0" }, "devDependencies": { "ava": "^2.4.0", "tsd": "^0.7.1", "xo": "^0.25.3" } } aggregate-error-3.0.1/readme.md000066400000000000000000000034311354555612100163570ustar00rootroot00000000000000# aggregate-error [![Build Status](https://travis-ci.org/sindresorhus/aggregate-error.svg?branch=master)](https://travis-ci.org/sindresorhus/aggregate-error) > Create an error from multiple errors ## Install ``` $ npm install aggregate-error ``` ## Usage ```js const AggregateError = require('aggregate-error'); const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]); throw error; /* AggregateError: Error: foo at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:33) Error: bar at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) Error: baz at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3) at Object. (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) at Module._compile (module.js:556:32) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.runMain (module.js:590:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) */ for (const individualError of error) { console.log(individualError); } //=> [Error: foo] //=> [Error: bar] //=> [Error: baz] ``` ## API ### AggregateError(errors) Returns an `Error` that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors. #### errors Type: `Array` If a string, a new `Error` is created with the string as the error message.
If a non-Error object, a new `Error` is created with all properties from the object copied over. aggregate-error-3.0.1/test.js000066400000000000000000000020121354555612100161070ustar00rootroot00000000000000import test from 'ava'; import AggregateError from '.'; test('main', t => { const error = new AggregateError([ new Error('foo'), 'bar', { message: 'baz', code: 'EBAZ' }, { code: 'EQUX' } ]); console.log(error); t.regex(error.message, /Error: foo\n {8}at /); t.regex(error.message, /Error: bar\n {8}at /); t.deepEqual([...error], [ new Error('foo'), new Error('bar'), Object.assign(new Error('baz'), {code: 'EBAZ'}), Object.assign(new Error(), {code: 'EQUX'}) ]); }); test('gracefully handle Error instances without a stack', t => { class StacklessError extends Error { constructor(...args) { super(...args); this.name = this.constructor.name; delete this.stack; } } const error = new AggregateError([ new Error('foo'), new StacklessError('stackless') ]); console.log(error); t.regex(error.message, /Error: foo\n {8}at /); t.regex(error.message, /StacklessError: stackless/); t.deepEqual([...error], [ new Error('foo'), new StacklessError('stackless') ]); });