fcs
2025-04-10 0163870d662dc5b7d69ceff977490ede594f7d82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'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) {
        // Even though strings are iterable, we don't allow them to prevent subtle user mistakes
        if (!errors[Symbol.iterator] || typeof errors === 'string') {
            throw new TypeError(`Expected input to be iterable, got ${typeof errors}`);
        }
 
        errors = Array.from(errors).map(err => err instanceof Error ? err : new Error(err));
 
        let message = errors.map(err => cleanInternalStack(cleanStack(err.stack))).join('\n');
        message = '\n' + indentString(message, 4);
 
        super(message);
        this.name = this.constructor.name;
        Object.defineProperty(this, '_errors', {value: errors});
    }
    * [Symbol.iterator]() {
        for (const error of this._errors) {
            yield error;
        }
    }
}
 
module.exports = AggregateError;