Skip to content

Add structured error types with errors.Is/errors.As support#74

Merged
jonbodner merged 3 commits intomasterfrom
feature/sentinel-errors
Feb 23, 2026
Merged

Add structured error types with errors.Is/errors.As support#74
jonbodner merged 3 commits intomasterfrom
feature/sentinel-errors

Conversation

@jonbodner
Copy link
Copy Markdown
Owner

@jonbodner jonbodner commented Feb 23, 2026

Summary

  • Replace all inline errors.New/fmt.Errorf calls with five typed error structs: ValidationError, QueryError, IdentifierError (root package) and ExtractError, AssignError (mapper package)
  • Each type uses an iota-based Kind field where the zero value acts as a wildcard, so errors.Is(err, ValidationError{}) matches any ValidationError and errors.Is(err, ValidationError{Kind: NotPointer}) matches exactly
  • ExtractError implements Unwrap() to surface wrapped strconv errors for InvalidIndex
  • Delete the cmp package, which did string-based error comparison; all tests updated to use errors.Is/errors.As
  • Add errors_test.go and mapper/errors_test.go covering kind matching, wildcard matching, errors.As extraction, and error message verification

Test plan

  • go build ./... passes
  • go test ./... passes
  • Verify errors.Is / errors.As behaviour in callers that previously used string matching

🤖 Generated with Claude Code

jonbodner and others added 3 commits February 23, 2026 17:38
Replace all inline errors.New/fmt.Errorf calls with typed error structs
(ValidationError, QueryError, IdentifierError, ExtractError, AssignError)
grouped by class with iota-based Kind fields. The zero value of each
Kind acts as a wildcard for errors.Is matching, enabling callers to
distinguish error conditions programmatically without string matching.

Delete the cmp package, which did string-based error comparison.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jonbodner jonbodner merged commit d867298 into master Feb 23, 2026
1 check passed
@jonbodner jonbodner deleted the feature/sentinel-errors branch February 23, 2026 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant