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.
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
Errorcause chaining pattern: when catching an error in an internal function, wrap it in a newErrorwith a semantic message and pass the original as{ cause }:This gives callers a clear, contextual message while preserving the full error chain for debugging. Requires the
es2022.errorlib for thecauseoption onError.Context
Identified during the DOM API isolation work (#784). Dropped to avoid a language version bump in that PR.