diff --git a/cmd/cosign/cli/sign/sign.go b/cmd/cosign/cli/sign/sign.go index ba286981d24..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 err == ociremote.ErrEntityNotFound { + 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 fab0a76588d..d279d38d26b 100644 --- a/pkg/oci/remote/remote.go +++ b/pkg/oci/remote/remote.go @@ -36,12 +36,24 @@ 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 = errors.New("entity not found in registry") ) +// 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 NewEntityNotFoundError(err error) error { + return &EntityNotFoundError{ + baseErr: err, + } +} + // SignedEntity provides access to a remote reference, and its signatures. // The SignedEntity will be one of SignedImage or SignedImageIndex. func SignedEntity(ref name.Reference, options ...Option) (oci.SignedEntity, error) { @@ -50,7 +62,7 @@ func SignedEntity(ref name.Reference, options ...Option) (oci.SignedEntity, erro got, err := remoteGet(ref, o.ROpt...) var te *transport.Error if errors.As(err, &te) && te.StatusCode == http.StatusNotFound { - return nil, ErrEntityNotFound + return nil, NewEntityNotFoundError(err) } else if err != nil { return nil, err }