fix(durable-sqlite): surface migration error via Error.cause on rollback#5776
Draft
spokodev wants to merge 1 commit into
Draft
fix(durable-sqlite): surface migration error via Error.cause on rollback#5776spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
`tx.rollback()` throws a sentinel `TransactionRollbackError` to abort the surrounding transaction. The previous code called `tx.rollback()` first and then `throw error`, so the second throw never executed and the caller only ever saw the generic "Rollback" message — the real cause (e.g. failed SQL statement) was lost. Wrap the rollback in a try and attach the original migration error as `rollbackError.cause` before re-throwing. Callers can now read `err.cause` to recover the underlying failure. Fixes drizzle-team#5763
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5763.
In the
durable-sqlitemigrator,tx.rollback()throws a sentinelTransactionRollbackErrorto abort the surrounding transaction. The previous code looked like:```ts
} catch (error: any) {
tx.rollback(); // throws TransactionRollbackError
throw error; // never reached
}
```
Because `tx.rollback()` throws synchronously, the `throw error` below it never executes. The caller only ever saw the generic `"Rollback"` message — the real cause (failed SQL statement, schema mismatch, etc.) was discarded. This matched the symptom @Craig-J described in #5763.
The fix wraps the rollback in a try/catch and attaches the original migration error as `rollbackError.cause` before re-throwing, so callers can recover the underlying failure:
```ts
} catch (error: any) {
try {
tx.rollback();
} catch (rollbackError: any) {
rollbackError.cause = error;
throw rollbackError;
}
throw error;
}
```
Behaviour change
Standalone verification (mocking the tx interface):
```
--- before ---
caller sees: TransactionRollbackError / Rollback
caller sees .cause: undefined
--- after ---
caller sees: TransactionRollbackError / Rollback
caller sees .cause: Migration 0003 failed: column "x" does not exist
```
Test plan