diff options
author | Michael Perrotte <mike@npmjs.com> | 2020-01-31 23:59:21 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-05-08 04:11:51 +0300 |
commit | 56e1f868e8634a4bf0f7a7186a68a6f3de9cfb2a (patch) | |
tree | f05cdcb56d66480641b6c8f8bb823bc10c6842df /node_modules/aggregate-error | |
parent | 8f6b6204f9cdbfc8e2a27a1c3b3f1591ac7e0d60 (diff) |
npm-pick-manifest@6.0.0
Diffstat (limited to 'node_modules/aggregate-error')
-rw-r--r-- | node_modules/aggregate-error/index.d.ts | 51 | ||||
-rw-r--r-- | node_modules/aggregate-error/index.js | 47 | ||||
-rw-r--r-- | node_modules/aggregate-error/license | 9 | ||||
-rw-r--r-- | node_modules/aggregate-error/package.json | 73 | ||||
-rw-r--r-- | node_modules/aggregate-error/readme.md | 61 |
5 files changed, 241 insertions, 0 deletions
diff --git a/node_modules/aggregate-error/index.d.ts b/node_modules/aggregate-error/index.d.ts new file mode 100644 index 000000000..2cec44a00 --- /dev/null +++ b/node_modules/aggregate-error/index.d.ts @@ -0,0 +1,51 @@ +/** +Create an error from multiple errors. +*/ +declare class AggregateError extends Error implements Iterable<Error> { + 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.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33) + // Error: bar + // at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) + // Error: baz + // at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) + // at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3) + // at Object.<anonymous> (/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<Error | {[key: string]: any} | string>); + + [Symbol.iterator](): IterableIterator<Error>; +} + +export = AggregateError; diff --git a/node_modules/aggregate-error/index.js b/node_modules/aggregate-error/index.js new file mode 100644 index 000000000..ba5bf0221 --- /dev/null +++ b/node_modules/aggregate-error/index.js @@ -0,0 +1,47 @@ +'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; diff --git a/node_modules/aggregate-error/license b/node_modules/aggregate-error/license new file mode 100644 index 000000000..e7af2f771 --- /dev/null +++ b/node_modules/aggregate-error/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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. diff --git a/node_modules/aggregate-error/package.json b/node_modules/aggregate-error/package.json new file mode 100644 index 000000000..f808df24b --- /dev/null +++ b/node_modules/aggregate-error/package.json @@ -0,0 +1,73 @@ +{ + "_from": "aggregate-error@^3.0.0", + "_id": "aggregate-error@3.0.1", + "_inBundle": false, + "_integrity": "sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA==", + "_location": "/aggregate-error", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "aggregate-error@^3.0.0", + "name": "aggregate-error", + "escapedName": "aggregate-error", + "rawSpec": "^3.0.0", + "saveSpec": null, + "fetchSpec": "^3.0.0" + }, + "_requiredBy": [ + "/p-map" + ], + "_resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz", + "_shasum": "db2fe7246e536f40d9b5442a39e117d7dd6a24e0", + "_spec": "aggregate-error@^3.0.0", + "_where": "/Users/mperrotte/npminc/cli/node_modules/p-map", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "bugs": { + "url": "https://github.com/sindresorhus/aggregate-error/issues" + }, + "bundleDependencies": false, + "dependencies": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + }, + "deprecated": false, + "description": "Create an error from multiple errors", + "devDependencies": { + "ava": "^2.4.0", + "tsd": "^0.7.1", + "xo": "^0.25.3" + }, + "engines": { + "node": ">=8" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "homepage": "https://github.com/sindresorhus/aggregate-error#readme", + "keywords": [ + "aggregate", + "error", + "combine", + "multiple", + "many", + "collection", + "iterable", + "iterator" + ], + "license": "MIT", + "name": "aggregate-error", + "repository": { + "type": "git", + "url": "git+https://github.com/sindresorhus/aggregate-error.git" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "version": "3.0.1" +} diff --git a/node_modules/aggregate-error/readme.md b/node_modules/aggregate-error/readme.md new file mode 100644 index 000000000..850de98a8 --- /dev/null +++ b/node_modules/aggregate-error/readme.md @@ -0,0 +1,61 @@ +# 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.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33) + Error: bar + at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) + Error: baz + at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) + at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3) + at Object.<anonymous> (/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<Error|Object|string>` + +If a string, a new `Error` is created with the string as the error message.<br> +If a non-Error object, a new `Error` is created with all properties from the object copied over. |