Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-persisted-lifecycle-durability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@tanstack/db-sqlite-persistence-core': patch
'@tanstack/electric-db-collection': patch
---

Fail-stop persisted collections when hydration or durability fails, while preserving lifecycle ownership across buffered and recovered sync work. Electric collections now surface these failures through the collection error state instead of continuing from an incomplete durable baseline.
6 changes: 6 additions & 0 deletions packages/db-sqlite-persistence-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ while still handling per-collection schema versions correctly.
- `InvalidPersistedStorageKeyError`
- `InvalidPersistedStorageKeyEncodingError`
- `PersistenceUnavailableError`
- `PersistenceDurabilityError`

Adapter commit failures reject the applied receipt and become the collection's
terminal sync error as `PersistenceDurabilityError`. The error preserves its
original `cause` and any available string `code` and `path`. Hydration and
source errors remain distinct and are not wrapped as durability errors.

## Typical usage (via runtime wrappers)

Expand Down
24 changes: 24 additions & 0 deletions packages/db-sqlite-persistence-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ export class PersistenceUnavailableError extends PersistedCollectionCoreError {
this.name = `PersistenceUnavailableError`
}
}

export class PersistenceDurabilityError extends PersistedCollectionCoreError {
readonly code: string | undefined
readonly path: string

constructor(cause: unknown, fallbackPath: string) {
const causeMessage =
cause instanceof Error ? cause.message : `Unknown persistence failure`
const causeRecord =
typeof cause === `object` && cause !== null
? (cause as Record<string, unknown>)
: undefined
const code =
typeof causeRecord?.code === `string` ? causeRecord.code : undefined
const path =
typeof causeRecord?.path === `string` ? causeRecord.path : fallbackPath

super(`Persistence durability failed at ${path}: ${causeMessage}`)
this.name = `PersistenceDurabilityError`
this.cause = cause
this.code = code
this.path = path
}
}
Loading
Loading