-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Inconsistent Error Handling Pattern
Priority: P2 - Medium
Estimate: 2 hours
Review Reference: REVIEW.md (P2-2)
Issue
Store interface methods use inconsistent error handling patterns:
// Three different patterns:
GetPool(ctx, id) (Pool, bool, error) // found flag + error
DeletePool(ctx, id) (bool, error) // success flag + error
CreatePool(ctx, in) (Pool, error) // just result + errorImpact: Low - Code consistency, but confusing for new contributors
Solution
Standardize to idiomatic Go:
- For Get operations: use
(T, error)withErrNotFoundsentinel error - For Delete: use
erroronly (returnErrNotFoundif applicable) - Define errors in domain package:
ErrNotFound,ErrHasChildren,ErrInUse
Example:
// internal/domain/errors.go
var (
ErrNotFound = errors.New("not found")
ErrHasChildren = errors.New("has child resources")
ErrInUse = errors.New("resource in use")
)
// Updated interface
func (m *MemoryStore) GetPool(ctx context.Context, id int64) (domain.Pool, error) {
m.mu.RLock()
defer m.mu.RUnlock()
p, ok := m.pools[id]
if !ok {
return domain.Pool{}, domain.ErrNotFound
}
return p, nil
}Acceptance Criteria
- domain/errors.go created with sentinel errors
- Store interface updated to use consistent patterns
- MemoryStore updated
- SQLite store updated
- Handlers updated to check errors with errors.Is()
- All tests updated
- Tests verify sentinel error checking
Files Affected
internal/domain/errors.go(new)internal/storage/store.gointernal/storage/sqlite/sqlite.gointernal/http/server.go(handler updates)- All test files
Validation
make test
make lint