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

fix: update error in SignedEntity to be more descriptive #3233

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cosign/cli/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ociremote.IsEntityNotFoundError(err) {
se = ociremote.SignedUnknown(digest)
} else if err != nil {
return fmt.Errorf("accessing image: %w", err)
Expand Down
13 changes: 11 additions & 2 deletions pkg/oci/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"net/http"
"strings"

"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
Expand All @@ -39,9 +40,17 @@ var (

// ErrEntityNotFound is the error that SignedEntity returns when the
// provided ref does not exist.
ErrEntityNotFound = errors.New("entity not found in registry")
ErrEntityNotFound = "cosign remoteGet: entity not found in registry"
vishal-chdhry marked this conversation as resolved.
Show resolved Hide resolved
)

func NewEntityNotFoundError(err error) error {
vishal-chdhry marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("%s error: %w", ErrEntityNotFound, err)
}

func IsEntityNotFoundError(err error) bool {
return strings.Contains(err.Error(), ErrEntityNotFound)
}

// 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) {
Expand All @@ -50,7 +59,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
}
Expand Down
Loading