diff --git a/cmd/cosign/cli/sign/sign.go b/cmd/cosign/cli/sign/sign.go index 847c42041e0..53c0fd3ccff 100644 --- a/cmd/cosign/cli/sign/sign.go +++ b/cmd/cosign/cli/sign/sign.go @@ -179,7 +179,7 @@ func SignCmd(ro *options.RootOptions, ko options.KeyOpts, signOpts options.SignO if digest, ok := ref.(name.Digest); ok && !signOpts.Recursive { se, err := ociremote.SignedEntity(ref, opts...) - if ociremote.IsEntityNotFoundError(err) { + if _, isEntityNotFoundErr := err.(*ociremote.EntityNotFoundError); isEntityNotFoundErr { se = ociremote.SignedUnknown(digest) } else if err != nil { return fmt.Errorf("accessing image: %w", err) diff --git a/pkg/oci/remote/remote.go b/pkg/oci/remote/remote.go index 02f0756f980..d279d38d26b 100644 --- a/pkg/oci/remote/remote.go +++ b/pkg/oci/remote/remote.go @@ -20,7 +20,6 @@ import ( "fmt" "io" "net/http" - "strings" "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" @@ -37,18 +36,22 @@ var ( remoteIndex = remote.Index remoteGet = remote.Get remoteWrite = remote.Write - - // ErrEntityNotFound is the error that SignedEntity returns when the - // provided ref does not exist. - ErrEntityNotFound = "cosign remoteGet: entity not found in registry" ) -func NewEntityNotFoundError(err error) error { - return fmt.Errorf("%s error: %w", ErrEntityNotFound, err) +// EntityNotFoundError is the error that SignedEntity returns when the +// provided ref does not exist. +type EntityNotFoundError struct { + baseErr error +} + +func (e *EntityNotFoundError) Error() string { + return fmt.Sprintf("entity not found in registry, error: %v", e.baseErr) } -func IsEntityNotFoundError(err error) bool { - return strings.Contains(err.Error(), ErrEntityNotFound) +func NewEntityNotFoundError(err error) error { + return &EntityNotFoundError{ + baseErr: err, + } } // SignedEntity provides access to a remote reference, and its signatures.