Summary
In commitPatchToLibsql(), errors from the batch flush are wrapped as:
s throw new Error("failed to execute sync batch", { cause });
This preserves the original error in .cause (ES2022), but the API handler (LibsqlQuadStore commit) does not unwrap .cause when throwing or logging. Downstream consumers may only check .message, potentially swallowing the root problem (e.g., a Turso network timeout, auth failure, or connection pool exhaustion).
Location
src/libsql/commit-patch-to-libsql.ts:139-143
s try { await batchExecutor.flush(); } catch (cause) { throw new Error("failed to execute sync batch", { cause }); }
The error propagates up through LibsqlQuadStore.createTransaction().commit() (libsql-quad-store.ts:73-102) without unwrapping .cause.
Evidence
Test "commitPatchToLibsql - flush error wrapping preserves original cause" in src/libsql/failure-point-tests.test.ts confirms .cause is set correctly — but no test verifies that the API surface or middleware inspects .cause.
Impact
- Low severity. The root cause is preserved in the standard .cause property and is inspectable by any caller that checks it. This gap is about observability hygiene, not data loss.
- During debugging, engineers may see "failed to execute sync batch" and miss the underlying "TURSO_NETWORK_TIMEOUT" signal.
Suggested Fix
Option A (in calling code): Unwrap .cause when logging or re-throwing in LibsqlQuadStore's commit handler.
Option B (in observability layer): Ensure the application's error reporting middleware (e.g., Sentry, OpenTelemetry) descends into .cause recursively. This is the more robust fix since many errors in the codebase use this pattern.
Related
Summary
In commitPatchToLibsql(), errors from the batch flush are wrapped as:
s throw new Error("failed to execute sync batch", { cause });This preserves the original error in .cause (ES2022), but the API handler (LibsqlQuadStore commit) does not unwrap .cause when throwing or logging. Downstream consumers may only check .message, potentially swallowing the root problem (e.g., a Turso network timeout, auth failure, or connection pool exhaustion).
Location
src/libsql/commit-patch-to-libsql.ts:139-143
s try { await batchExecutor.flush(); } catch (cause) { throw new Error("failed to execute sync batch", { cause }); }The error propagates up through LibsqlQuadStore.createTransaction().commit() (libsql-quad-store.ts:73-102) without unwrapping .cause.
Evidence
Test "commitPatchToLibsql - flush error wrapping preserves original cause" in src/libsql/failure-point-tests.test.ts confirms .cause is set correctly — but no test verifies that the API surface or middleware inspects .cause.
Impact
Suggested Fix
Option A (in calling code): Unwrap .cause when logging or re-throwing in LibsqlQuadStore's commit handler.
Option B (in observability layer): Ensure the application's error reporting middleware (e.g., Sentry, OpenTelemetry) descends into .cause recursively. This is the more robust fix since many errors in the codebase use this pattern.
Related