Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ErrBadName checkable via errors.Is() #1462

Merged
merged 2 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/name/errors.go
Expand Up @@ -28,6 +28,12 @@ func (e *ErrBadName) Error() string {
return e.info
}

// Is reports whether target is an error of type ErrBadName
func (e *ErrBadName) Is(target error) bool {
var berr *ErrBadName
return errors.As(target, &berr)
}

// newErrBadName returns a ErrBadName which returns the given formatted string from Error().
func newErrBadName(fmtStr string, args ...interface{}) *ErrBadName {
return &ErrBadName{fmt.Sprintf(fmtStr, args...)}
Expand Down
3 changes: 3 additions & 0 deletions pkg/name/errors_test.go
Expand Up @@ -31,4 +31,7 @@ func TestBadName(t *testing.T) {
if err.Error() != "could not parse reference: @@" {
t.Errorf("Unexpected string: %v", err)
}
if !errors.Is(err, &ErrBadName{}) {
t.Errorf("Not an ErrBadName using errors.Is: %v", err)
}
}