CKTIS / JavaScript
AggregateError: multiple failures in one exception
AggregateError groups failures from a batch operation while retaining an individual errors list and optional message and cause.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
new AggregateError(errors[, message[, options]])new AggregateError(errors, message, options) consumes the iterable errors and stores its values in the errors array. message is optional text and options.cause records a higher-level cause. Construction returns an error object; it does not throw the contained failures automatically.
Use it when one operation can fail independently in several places, as with Promise.any. Code catching an AggregateError normally iterates error.errors. A non-iterable first argument throws TypeError; members of the iterable are not required to be Error objects.
An empty iterable is valid. When message is omitted the instance need not have its own message property, and cause is created only when supplied. The example combines two different error classes without losing the batch message.
Examples
const failures = [new Error("disk"), new TypeError("format")];
const error = new AggregateError(failures, "Import failed", {cause: "batch-7"});
console.log(error.name);
console.log(error.message);
console.log(error.errors.map(item => item.name).join(","));
console.log(error.cause);Result
AggregateError Import failed Error,TypeError batch-7