Skip to content

Commit fd92b01

Browse files
committed
fix: applying suggestions from @Wwwsylvia
Signed-off-by: Kyle M. Tarplee <kmtarplee@ieee.org>
1 parent fc50894 commit fd92b01

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

registry/remote/repository.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,12 @@ func (r *Repository) Referrers(ctx context.Context, desc ocispec.Descriptor, art
483483

484484
// The referrers state is unknown.
485485
if err != nil {
486-
if !errors.Is(err, errdef.ErrUnsupported) {
487-
return err
488-
}
489-
if errutil.IsErrorCode(err, errcode.ErrorCodeNameUnknown) {
490-
// The repository is not found, no fallback.
491-
return err
486+
if errors.Is(err, errdef.ErrUnsupported) {
487+
// Referrers API is not supported, fallback to referrers tag schema.
488+
r.SetReferrersCapability(false)
489+
return r.referrersByTagSchema(ctx, desc, artifactType, fn)
492490
}
491+
return err
493492
// Fallback to referrers tag schema.
494493
r.SetReferrersCapability(false)
495494
return r.referrersByTagSchema(ctx, desc, artifactType, fn)
@@ -545,16 +544,19 @@ func (r *Repository) referrersPageByAPI(ctx context.Context, artifactType string
545544
switch resp.StatusCode {
546545
case http.StatusOK:
547546
case http.StatusNotFound:
548-
// A 404 returned by Referrers API indicates that Referrers API is not supported.
549-
return "", errors.Join(errdef.ErrUnsupported, errutil.ParseErrorResponse(resp))
547+
if errResp := errutil.ParseErrorResponse(resp); errutil.IsErrorCode(errResp, errcode.ErrorCodeNameUnknown) {
548+
// The repository is not found, Referrers API status is unknown
549+
return "", errResp
550+
}
551+
// Referrers API is not supported.
552+
return "", fmt.Errorf("failed to query referrers API: %w", errdef.ErrUnsupported)
550553
default:
551554
return "", errutil.ParseErrorResponse(resp)
552555
}
553556

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

560562
var index ocispec.Index

0 commit comments

Comments
 (0)