Skip to content

Adopt Error cause chaining for better error context #804

Description

@kraenhansen

Problem

Several places in the codebase catch errors and either log-and-rethrow (double-logging) or lose context by throwing a new error without linking to the original cause.

Proposed solution

Adopt the Error cause chaining pattern: when catching an error in an internal function, wrap it in a new Error with a semantic message and pass the original as { cause }:

throw new Error("Failed to start microphone streaming", { cause: error });

This gives callers a clear, contextual message while preserving the full error chain for debugging. Requires the es2022.error lib for the cause option on Error.

Context

Identified during the DOM API isolation work (#784). Dropped to avoid a language version bump in that PR.

Metadata

Metadata

Assignees

Labels

@elevenlabs/clientIssues and PRs related to the `@elevenlabs/client` package.refactorCode refactoring or restructuring

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions