Skip to content

Commit

Permalink
fix: applying suggestions from @Wwwsylvia
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle M. Tarplee <[email protected]>
  • Loading branch information
ktarplee committed Nov 17, 2023
1 parent fc50894 commit fd92b01
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions registry/remote/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,12 @@ func (r *Repository) Referrers(ctx context.Context, desc ocispec.Descriptor, art

// The referrers state is unknown.
if err != nil {
if !errors.Is(err, errdef.ErrUnsupported) {
return err
}
if errutil.IsErrorCode(err, errcode.ErrorCodeNameUnknown) {
// The repository is not found, no fallback.
return err
if errors.Is(err, errdef.ErrUnsupported) {
// Referrers API is not supported, fallback to referrers tag schema.
r.SetReferrersCapability(false)
return r.referrersByTagSchema(ctx, desc, artifactType, fn)
}
return err
// Fallback to referrers tag schema.
r.SetReferrersCapability(false)
return r.referrersByTagSchema(ctx, desc, artifactType, fn)
Expand Down Expand Up @@ -545,16 +544,19 @@ func (r *Repository) referrersPageByAPI(ctx context.Context, artifactType string
switch resp.StatusCode {
case http.StatusOK:
case http.StatusNotFound:
// A 404 returned by Referrers API indicates that Referrers API is not supported.
return "", errors.Join(errdef.ErrUnsupported, errutil.ParseErrorResponse(resp))
if errResp := errutil.ParseErrorResponse(resp); errutil.IsErrorCode(errResp, errcode.ErrorCodeNameUnknown) {
// The repository is not found, Referrers API status is unknown
return "", errResp
}
// Referrers API is not supported.
return "", fmt.Errorf("failed to query referrers API: %w", errdef.ErrUnsupported)
default:
return "", errutil.ParseErrorResponse(resp)
}

// also check the content type
if ct := resp.Header.Get("Content-Type"); ct != ocispec.MediaTypeImageIndex {
err := errors.Join(errdef.ErrUnsupported, errutil.ParseErrorResponse(resp))
return "", fmt.Errorf("unknown content returned (%s), expecting image index: %w", ct, err)
return "", fmt.Errorf("unknown content returned (%s), expecting image index: %w", ct, errdef.ErrUnsupported)
}

var index ocispec.Index
Expand Down

0 comments on commit fd92b01

Please sign in to comment.