fix: a few random crash fixes - #1628
Conversation
The request-ID type assertion panicked when the RequestID middleware didn't run first. Use the comma-ok form so the trace ID is just empty. Also default the log spy's status to 200, so responses that write a body without calling WriteHeader aren't logged as status 0.
NewGroupRepository never set the attachments field, so GroupDelete hit a nil pointer as soon as a group's entities had an attachment. Pass the AttachmentRepo through the constructor like EntityRepository does. That also exposed a deadlock: AttachmentRepo.Delete uses the base connection, so running it inside the tx blocks on single-writer SQLite. Do the attachment deletes before opening the tx. The rows still cascade with the entity delete, so nothing is left behind.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
WalkthroughGroup deletion now cleans up attachments within the active transaction and rolls back failed initial queries. Primary attachment updates also use the transaction client, while error formatting and HTTP middleware tolerate nil errors and unexpected request values. ChangesRepository transaction integrity
Error and request logging robustness
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
✨ Simplify code
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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/internal/data/repo/repo_group.go`:
- Around line 329-349: The group deletion flow around the attachment cleanup
loop and transaction must stop deleting blobs before the transaction or
continuing after cleanup errors. Make entity/group row deletion and durable
blob-cleanup intents part of the same transaction, then execute or retry blob
removals only after a successful commit, ensuring newly-created attachments and
transaction failures do not leave inconsistent cleanup state.
In `@backend/internal/sys/validate/errors.go`:
- Around line 63-66: Update RequestError.Error to return a non-empty fallback
when Err is nil and Status is 0, preferably by using http.StatusBadRequest
before calling http.StatusText. Add coverage for NewRequestError(nil, 0) that
verifies the returned error message is non-empty.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bec2fbc9-9a82-4dbd-93a0-f44021aa491b
📒 Files selected for processing (5)
backend/internal/data/repo/repo_group.gobackend/internal/data/repo/repos_all.gobackend/internal/sys/validate/errors.gobackend/internal/web/mid/errors.gobackend/internal/web/mid/logger.go
|
I found some more thingies @coderabbitai review |
|
✅ Action performedReview finished.
|
What type of PR is this?
What this PR does / why we need it:
Four fixes found while writing tests, one commit each.
validate —
RequestError.Error()panicked whenErrwas nil. Guard it, fall back to status text.middleware — bare
.(string)on the request-ID key panics if chi'sRequestIDmiddleware didn't run; switched to comma-ok. Also the logger spy didn't overrideWrite, so implicit-200 responses logged as status 0.repo —
NewGroupRepositorynever set attachments, so deleting a group with attachments panicked. Wired it through the constructor. Attachment deletes now use the transaction-bound client, avoiding the SQLite deadlock while keeping the database work in one transaction.attachments — clearing the previous primary photo during attachment creation used the base client instead of the existing transaction. Run it through the transaction too.
Which issue(s) this PR fixes:
None.
Testing
go test