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 all 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 _, isEntityNotFoundErr := err.(*ociremote.EntityNotFoundError); isEntityNotFoundErr {
se = ociremote.SignedUnknown(digest)
} else if err != nil {
return fmt.Errorf("accessing image: %w", err)
Expand Down
22 changes: 17 additions & 5 deletions pkg/oci/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
Loading