fix(purchases): don't leak raw persistence error into audit-gap status (refs #623) - #628
Conversation
recordHistoryAuditGap embedded the raw SavePurchaseHistory error (histErr)
verbatim into exec.Error, which is surfaced to clients via the history
status_description. That leaks internal storage details (e.g. SQL constraint
text) to the UI.
Log histErr server-side via logging.Errorf for diagnosis, and store only a
generic user-safe note ("commitment X purchased but its history record failed
to save") in exec.Error. Extends the existing audit-gap regression test with
NotContains assertions so the raw error text can never reach the user-facing
field again.
Follow-up to the CodeRabbit review on #623 (landed at merge time).
|
@coderabbitai review |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughError sanitization in purchase history failure path: when ChangesPurchase History Audit Gap Error Sanitization
Estimated Code Review Effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly Related PRs
Suggested Labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
✅ Actions performedReview triggered.
|
Summary
Follow-up to a CodeRabbit review comment on #623 that landed right at merge time, so it couldn't be folded into that PR.
recordHistoryAuditGap(added in #623) embedded the rawSavePurchaseHistoryerror (histErr) verbatim intoexec.Error. That field is surfaced to clients via the historystatus_description, so an internal storage error (e.g. SQL constraint text likemonthly_cost violates not-null constraint) leaked to the UI.Fix
histErrserver-side vialogging.Errorffor diagnosis.exec.Error("commitment X purchased but its history record failed to save") with no raw error interpolation.TestManager_ExecuteAndFinalize_HistorySaveFailure_StaysVisible) withNotContainsassertions on the raw error text, so it fails-on-regression if the leak is reintroduced.The #621 invariants are preserved: a history-write failure still keeps the completed purchase visible (the note is still recorded), the execution still stays
completed(notfailed), and dollar totals are unaffected.Test plan
go test ./internal/purchase/ -run TestManager_ExecuteAndFinalize_HistorySaveFailure_StaysVisiblepasses; the newNotContainsassertions fail against the pre-fix codegofmt/go vetcleanRefs #623.
Summary by CodeRabbit
Release Notes