db: fix db.Initialize() sqlite3 error checking, add errortype linter#6477
db: fix db.Initialize() sqlite3 error checking, add errortype linter#6477cce merged 2 commits intoalgorand:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in SQLite error handling and adds the errortype linter to prevent similar issues in the future. The bug involved incorrectly using errors.As with a pointer type for sqlite3.Error, which doesn't implement the error interface via pointer receiver methods.
- Fixed
sqlite3.Errortype declaration inutil/db/initialize.gofrom pointer to value type - Added
errortypelinter configuration to catch error handling bugs - Updated
TransactionInLedgerError.Error()to use pointer receiver for consistency - Added compile-time checks verifying error interface implementations
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| util/db/initialize.go | Changed sqlite3.Error from pointer to value type to fix errors.As usage |
| ledger/ledgercore/error.go | Added error interface verification checks and changed TransactionInLedgerError.Error() to pointer receiver |
| .golangci-warnings.yml | Added errortype linter configuration with appropriate settings |
| .custom-gcl.yml | Added errortype plugin dependency configuration |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6477 +/- ##
==========================================
+ Coverage 47.05% 47.28% +0.22%
==========================================
Files 667 659 -8
Lines 88831 88225 -606
==========================================
- Hits 41802 41713 -89
+ Misses 44284 43745 -539
- Partials 2745 2767 +22 ☔ View full report in Codecov by Sentry. |
Summary
While working on #6466, I discovered a bug where error-handling wasn't working as I intended because I was misusing
errors.Ason a pointer error-type (that implemented theerrorinterface using value receiver methods).This
errortypelinter would have caught the bug, added here to our custom warning linter.It also caught a similar bug handling
sqlite3.Errorin util/db/initialize.go, fixed here.Test Plan
Existing tests should pass.