AggregateError
In JavaScript, AggregateError is the native error type that the engine throws when several errors need to be reported as one, most often when every promise passed to Promise.any() rejects. It extends Error, so it carries a message, a name, and a stack trace, plus an errors array that holds the individual errors. An empty list of promises is enough to produce one:
> await Promise.any([])
Uncaught [AggregateError: All promises were rejected] { [errors]: [] }
AggregateError was added in ES2021 together with Promise.any(), and it’s Baseline Widely available.
When JavaScript Throws AggregateError
The engine creates an AggregateError only at run time, never while parsing. It shows up in these situations:
Promise.any(): The returned promise rejects with anAggregateErrorwhen every input promise rejects, or when the iterable is empty. Itserrorsarray lists the rejection reasons in input order.- Application code: A function that checks several things, such as the fields of a form, throws one
AggregateErrorto report every failure at once. - Node.js sockets: A connection to a host name that resolves to several addresses, such as
localhoston IPv4 and IPv6, fails with anAggregateErrorwhen the connection to every address is refused or times out.
The specification doesn’t set a message for the Promise.any() case, so each engine words it differently, as the table below shows.
Syntax
The constructor takes the list of errors first, then an optional message and options:
new AggregateError(<errors>[, <message>[, <options>]])
| Parameter | Description |
|---|---|
errors |
Required. An iterable of errors, usually an array. The items don’t have to be Error instances. A value that isn’t iterable throws a TypeError. |
message |
Optional. A description of the whole failure. Defaults to an empty string. |
options |
Optional. An object whose cause property sets the error’s .cause, as with Error. |
The constructor works with or without new and returns a new error either way. It copies errors into a new array and stores it as a non-enumerable .errors property, which is why Node.js prints it as [errors].
Say a signup form fails two checks, and the code reports both of them in one error:
> const signupError = new AggregateError(
… [new Error("Email is missing"), new Error("Password is too short")],
… "Signup form has 2 problems",
… );
undefined
> signupError.message
'Signup form has 2 problems'
> signupError.errors.map((error) => error.message)
[ 'Email is missing', 'Password is too short' ]
At the Node.js REPL, evaluating signupError itself shows the message, the stack trace, and every nested error under [errors].
Catching AggregateError
Say a client downloads a file from whichever mirror answers first, and every mirror is down. The handler checks for AggregateError, rethrows anything else, and collects the reasons:
> const download = async (mirror) => {
… throw new Error(`${mirror} is down`);
… };
undefined
> await Promise.any(["eu", "us"].map(download)).catch((error) => {
… if (!(error instanceof AggregateError)) throw error;
… return error.errors.map((reason) => reason.message);
… })
[ 'eu is down', 'us is down' ]
The instanceof check fails for errors from another realm, such as an iframe or a node:vm context, while error.name and Error.isError() still work. Inside an async function, a try statement around await Promise.any() catches the same error.
Common Messages
V8 and Node.js print these messages with AggregateError:
| Message (V8) | Usual Cause | Fix |
|---|---|---|
All promises were rejected |
Promise.any() got an empty iterable, or every promise in it rejected |
Read .errors for each rejection reason, and pass at least one promise that can fulfill |
Empty, printed as AggregateError [ECONNREFUSED]: |
Node.js: every address of a host such as localhost refused the connection |
Start the server or fix the port, then read .errors for each address |
Empty, printed as AggregateError [ETIMEDOUT]: |
Node.js: no address of the host answered before the connection timed out | Check the host, the firewall, and the network, then read .errors for each address |
Firefox and Safari word the Promise.any() rejection differently:
| V8 | Firefox (SpiderMonkey) | Safari (JavaScriptCore) |
|---|---|---|
All promises were rejected |
No Promise in Promise.any was resolved |
Empty, printed as AggregateError |
In every engine, the message only says that everything failed. The reasons live in .errors, so log that array first when Promise.any() rejects.
Related Resources
Course
JavaScript Error Handling in Depth for Pythonistas
Port a food bank's all-or-nothing donation import from Python to JavaScript, and learn to define error classes, chain errors with cause, report many errors at once, and use a debugger.
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 12, 2026