Sha256: 84c72b3601fccebd43285959f9085ad3e4af0d5683613dd125ce8e56b7aa8185

Contents?: true

Size: 1.22 KB

Versions: 50

Compression:

Stored size: 1.22 KB

Contents

'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;

Version data entries

50 entries across 49 versions & 7 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.59 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.58 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.57 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.56 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.55 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.54 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.53 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.52 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.51 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.50 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.49 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.48 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.47 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.46 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.45 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.44 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.43 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.42 node_modules/aggregate-error/index.js
immosquare-cleaner-0.1.41 node_modules/aggregate-error/index.js