diff --git a/pkg/name/errors.go b/pkg/name/errors.go index 035e35069..35a25847f 100644 --- a/pkg/name/errors.go +++ b/pkg/name/errors.go @@ -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...)} diff --git a/pkg/name/errors_test.go b/pkg/name/errors_test.go index 8ee6d4d8e..6ceb4590c 100644 --- a/pkg/name/errors_test.go +++ b/pkg/name/errors_test.go @@ -31,4 +31,8 @@ func TestBadName(t *testing.T) { if err.Error() != "could not parse reference: @@" { t.Errorf("Unexpected string: %v", err) } + //var cerr *ErrBadName + if !errors.Is(err, &ErrBadName{}) { + t.Errorf("Not an ErrBadName using errors.Is: %v", err) + } }