Skip to content

P2: Standardize error handling patterns #69

@BadgerOps

Description

@BadgerOps

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 + error

Impact: Low - Code consistency, but confusing for new contributors

Solution

Standardize to idiomatic Go:

  • For Get operations: use (T, error) with ErrNotFound sentinel error
  • For Delete: use error only (return ErrNotFound if 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.go
  • internal/storage/sqlite/sqlite.go
  • internal/http/server.go (handler updates)
  • All test files

Validation

make test
make lint

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions