The BugSplat JavaScript SDK Now Reports Error.cause Chains
CTO at BugSplat
JavaScript code wraps errors all the time. A database driver throws a low-level error, a data layer catches the low-level error and throws a friendlier one, and a route handler does the same again. Since ES2022, JavaScript has had a standard place to keep the original error: the cause property. The error at the end of a cause chain is usually the error that explains the failure.
We recently released version 9.2 of the BugSplat JavaScript SDK, which reports the whole Error.cause chain. When your app posts an error, the crash report shows every linked error with its own call stack, and the root cause names the crash. Error chains work in browser and Node.js apps, and in the BugSplat SDKs for React, Angular, Expo, and Electron.
What's New
Error.causechains are captured bypost()with nothing to configure.- The root cause names the crash. The Exception Code and Exception Message come from the innermost error.
- A call stack for every linked error, each under its own
Caused by:row. - Error properties as locals, such as a database driver's
codeandconstraint_name. - Properties of the error you posted become attributes that you can search and filter by.
- Source maps apply to every linked call stack.
AggregateErrorsupport.- Real function names for
asyncframes, constructors, and aliased methods.
A Wrapped Database Error
Say your sign-up route wraps a database failure before rethrowing the failure:
async function createAccount(user: NewUser) {
try {
return await sql`insert into users ${sql(user)}`;
} catch (error) {
throw new Error('Failed to create account', { cause: error });
}
}
When the wrapped error reaches bugsplat.post(), the crash report lists the call stack of the error you posted, starting at createAccount. A Caused by: PostgresError row follows, and then the call stack of the PostgresError.
Here are the details of the crash report for a sign-up with an email address that already exists. The Exception Code and the Exception Message come from the PostgresError:

What a Crash Report Contains
- The root cause names the crash. The Exception Code and Exception Message come from the innermost error. Your list of crash reports shows
PostgresErrorandduplicate key value violates unique constraint "users_email_key", where a report of the outermost error alone would showErrorandFailed to create account. - Every linked error keeps its own call stack. Each linked error follows a
Caused by:row, so you can see where each layer of your code threw. - Properties become locals. Expand a
Caused by:row to see the linked error's message and own properties, such as a database driver'scode,constraint_name, ordetail. - Properties of the error you posted become attributes. Properties you attach before rethrowing, such as a
requestIdor aroute, are added to the crash report's attributes, so you can search and filter byrequestIdorroute. Attributes you pass topost()take precedence. - Source maps apply to every call stack. If you upload source maps for the version, the call stack of each linked error is mapped back to your original source.
Here is the call stack of the same crash report, with the Caused by: PostgresError row expanded to show the locals:

An error chain also follows the errors of an AggregateError, such as an AggregateError from Promise.any. A cause that is a string or a plain object is recorded with its type and message.
How Error Chains Affect Grouping
BugSplat still groups a crash by the function name and line number of the error you posted, so error chains do not move your existing crashes into new groups.
A Caused by: row is named for the error's type only, and the error's message appears in the row's locals. Two crashes whose causes differ only in an IP address, a URL, or a record ID stay in one group.
Auto-grouping rules apply across the chain. If an auto-grouping rule ignores every frame of the error you posted, for example a rule that ignores **/node_modules/**, grouping continues into the call stacks of the linked errors and skips the Caused by: rows.
Function Names for Async Frames
Call stacks from V8 now show the real function name for async frames, for constructors such as new PostgresError, and for methods called through an alias. New crashes with an async frame, a constructor frame, or an aliased method frame are grouped under the real function name, so an existing async(...) or new(...) group stops growing.
Get Started
Error chains require version 9.2.0 or later of the bugsplat package:
npm install bugsplat@latest
- Node.js: import
BugSplatNodefrombugsplat/node. - React:
@bugsplat/reactreports errors throughbugsplat. Runnpm updateso that your lockfile resolvesbugsplat9.2.0 or later. - Angular: install the new
@bugsplat/angularpackage, which replacesbugsplat-ngand requires Angular 22 or later. The Angular guide has the setup steps. - Expo:
@bugsplat/exporeports errors through@bugsplat/react, so the samenpm updateapplies. - Electron:
@bugsplat/electroncaptures error chains in the main process and in every renderer. The Electron guide has the setup steps.
The Error Chains section of the JavaScript guide covers error chains in more detail. If you see an error chain that BugSplat reports badly, email support@bugsplat.com and tell us what happened.