Fix transaction commit() to throw errors instead of swallowing them#558
Fix transaction commit() to throw errors instead of swallowing them#558KyleAMathews merged 7 commits intomainfrom
Conversation
Previously, when a transaction's mutationFn threw an error, commit() would catch it, rollback the transaction, and return the failed transaction. This was inconsistent with documented error handling patterns. Now commit() properly re-throws errors after rolling back, allowing both `await tx.commit()` and `await tx.isPersisted.promise` to work correctly in try/catch blocks. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🦋 Changeset detectedLatest commit: 01b8296 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +18 B (+0.03%) Total Size: 66.7 kB
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 1.18 kB ℹ️ View Unchanged
|
…wing - Fixed test that wasn't setting autoCommit: false for manual commit - Updated other transaction tests to properly await commit() calls - Added .catch() to autoCommit logic to prevent unhandled rejections - All tests now pass without unhandled promise rejections 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ve tests Based on feedback, made the following improvements: 1. Preserve original error identity when throwing from commit() - Capture the original error before rollback - Throw the exact same error instance to maintain stack traces 2. Add comprehensive error handling tests: - Verify commit() and isPersisted.promise reject with same error instance - Handle non-Error throwables (strings, numbers, objects) - Test idempotence - calling commit() on completed/failed transactions - Test cascading rollbacks with proper error propagation 3. Fix cascading rollback behavior - Secondary rollbacks now correctly reject isPersisted.promise - tx2 rejects with undefined when rolled back due to tx1's failure This ensures error handling is consistent, predictable, and maintains error identity for better debugging. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Since commit() now throws errors instead of returning a failed transaction, this is a breaking change that requires a minor version bump. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
|
@pubkey tests started failing for the rxdb-collection — could you look at that when you have a chance? |
|
@KyleAMathews Your test stores data that does not match the schema of the test-RxDB-database: So there is an additional property called |
samwillis
left a comment
There was a problem hiding this comment.
Other than the failing test with rxdb this look good to me.
|
Just got in a bit deeper. I think the problem is not the rxdb-adapter but how this change is handling errors and how vitest expects all errors to be catched/handled. The reason why the rxdb-adapter fails seems to be because it is really testing the correct persistence-write-behavior on wrong data. await expect(async () => {
const tx = await collection.insert({
id: `3`,
name: `invalid`,
foo: `bar`,
})
await tx.isPersisted.promise
}).rejects.toThrow(/schema validation error/) |
|
@pubkey ok, I skipped the test for now. |
…anStack#558) Co-authored-by: Claude <[email protected]>
Summary
Background
Previously, when a transaction's mutationFn threw an error, the commit() method would catch it, rollback the transaction, and return the failed transaction instead of re-throwing the error. This made it inconsistent with the documented error handling patterns shown in the docs.
Changes
await tx.commit()andawait tx.isPersisted.promisework correctly in try/catch blocksTest plan
🤖 Generated with Claude Code