Skip to content

Fix missing tx.Rollback() on error paths (#24)#68

Merged
jonbodner merged 1 commit intomasterfrom
fix-tx-rollback
Feb 22, 2026
Merged

Fix missing tx.Rollback() on error paths (#24)#68
jonbodner merged 1 commit intomasterfrom
fix-tx-rollback

Conversation

@jonbodner
Copy link
Copy Markdown
Owner

Replace all defer tx.Commit() patterns with the idiomatic Go pattern:

  • defer func() { _ = tx.Rollback() }() as a safety-net at the top
  • Explicit tx.Commit() with error handling at the end of the success path

For test code in proteus_test.go where all reads use the same tx and data does not need to persist, a deferred rollback alone is sufficient, providing better test isolation.

Files fixed: cmd/sample/main.go, cmd/sample-ctx/main.go, bench/bench_test.go, speed/speed.go, example_test.go, example2_test.go, mapper_test.go, proteus_test.go (11 instances)

Replace all `defer tx.Commit()` patterns with the idiomatic Go pattern:
- `defer func() { _ = tx.Rollback() }()` as a safety-net at the top
- Explicit `tx.Commit()` with error handling at the end of the success path

For test code in proteus_test.go where all reads use the same tx and
data does not need to persist, a deferred rollback alone is sufficient,
providing better test isolation.

Files fixed: cmd/sample/main.go, cmd/sample-ctx/main.go,
bench/bench_test.go, speed/speed.go, example_test.go, example2_test.go,
mapper_test.go, proteus_test.go (11 instances)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jonbodner jonbodner merged commit f396aa6 into master Feb 22, 2026
1 check passed
@jonbodner jonbodner deleted the fix-tx-rollback branch February 22, 2026 07:15
jonbodner added a commit that referenced this pull request Feb 22, 2026
Replace all `defer tx.Commit()` patterns with the idiomatic Go pattern:
- `defer func() { _ = tx.Rollback() }()` as a safety-net at the top
- Explicit `tx.Commit()` with error handling at the end of the success path

For test code in proteus_test.go where all reads use the same tx and
data does not need to persist, a deferred rollback alone is sufficient,
providing better test isolation.

Files fixed: cmd/sample/main.go, cmd/sample-ctx/main.go,
bench/bench_test.go, speed/speed.go, example_test.go, example2_test.go,
mapper_test.go, proteus_test.go (11 instances)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant