Add structured error types with errors.Is/errors.As support#74
Merged
Add structured error types with errors.Is/errors.As support#74
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
errors.New/fmt.Errorfcalls with five typed error structs:ValidationError,QueryError,IdentifierError(root package) andExtractError,AssignError(mapper package)Kindfield where the zero value acts as a wildcard, soerrors.Is(err, ValidationError{})matches anyValidationErroranderrors.Is(err, ValidationError{Kind: NotPointer})matches exactlyExtractErrorimplementsUnwrap()to surface wrapped strconv errors forInvalidIndexcmppackage, which did string-based error comparison; all tests updated to useerrors.Is/errors.Aserrors_test.goandmapper/errors_test.gocovering kind matching, wildcard matching,errors.Asextraction, and error message verificationTest plan
go build ./...passesgo test ./...passeserrors.Is/errors.Asbehaviour in callers that previously used string matching🤖 Generated with Claude Code