fix(db): report rollback outcome correctly in WithTxn - #1855
Conversation
WithTxn wrapped every failed transaction as a rollback failure with a nil rollback error in the message and added the "rollback:" prefix twice. Check the rollback's own error instead, wrap once, and drop the dead error writes in the panic path. Fix inverted error assertions in the user repository tests that the double wrap was masking. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis change fixes ChangesTransaction error handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (1 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report for CI Build 30987023694Coverage increased (+0.06%) to 47.585%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
rohilsurana
left a comment
There was a problem hiding this comment.
Review
Clean, well-scoped bugfix. WithTxn used to report every failed transaction as a rollback failure. It printed the nil rollback error as %!s(<nil>) and added a duplicate rollback: prefix. This PR fixes all three underlying problems: the wrong variable in the condition, the double wrap, and the dead assignments in the panic path. It also adds a focused test and corrects the inverted assertions in user_repository_test.go.
What I checked
errors.Is/errors.Asmatching is preserved. The callback error stays wrapped with%won every path, so downstream matching does not change.- No caller depends on the old message. The only
rollback:match in non-test code is an unrelated comment incore/serviceuser/service.go. - Panic path behavior is identical. The deferred func re-panics, so the named
errreturn is never observed by the caller. Dropping those assignments changes nothing. - Test coverage is strong. Commit, begin failure, rollback success and failure with exact messages, commit failure, and panic are all covered. The exact-message asserts guard against the
%!s(<nil>)regression directly.
Verdict
Looks good to merge. There is one minor, non-blocking suggestion inline about making the rollback error matchable with errors.Is. The other inline notes are just clarifications for the review. Nice catch on the inverted errors.Unwrap(err) == tc.Err asserts too.
Both the rollback error and the callback error are now matchable with errors.Is. The message text is unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
WithTxninpkg/dbreported every failed transaction as a rollback failure: the message embedded a nil rollback error (%!s(<nil>)) and carried a duplicaterollback:prefix.Fixes #1765
Changes
rlbErr) instead of the already non-nil callback error when building the returned message.pkg/db/db_test.gocovering commit, begin failure, rollback success and failure messages, commit failure, and panic handling, using a fakedatabase/sql/driver(no new dependencies).internal/store/postgres/user_repository_test.go:errors.Unwrap(err) == tc.Errfailed the test when the error matched, and the old double wrap kept it from firing. Now!errors.Is(err, tc.Err).Technical Details
The callback error stays wrapped with
%won all paths, soerrors.Is/errors.Asmatching is unchanged. Messages now are:rollback: <callback error>rollback error: <rollback error> while executing: <callback error>Test Plan
go test -race -count=2 ./pkg/db/passesgo test ./internal/store/postgres/passesgolangci-lint run ./pkg/db/... ./internal/store/postgres/...reports no issues🤖 Generated with Claude Code