From f14ddf054cc8e5edbe0e352a32f557f29f7c7666 Mon Sep 17 00:00:00 2001 From: "Sergio C. Arteaga" Date: Wed, 22 Sep 2021 17:21:58 +0200 Subject: [PATCH] Fix issue tracking some warnings as errors (#1563) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergio CastaƱo Arteaga --- internal/repo/manager.go | 3 +++ internal/tracker/source/helm/helm.go | 3 +++ internal/util/oci.go | 12 ++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/repo/manager.go b/internal/repo/manager.go index 62cf4887..95ea032e 100644 --- a/internal/repo/manager.go +++ b/internal/repo/manager.go @@ -365,6 +365,9 @@ func (m *Manager) GetMetadata(mdFile string) (*hub.RepositoryMetadata, error) { defer cancel() ref := fmt.Sprintf("%s:%s", strings.TrimPrefix(mdFile, hub.RepositoryOCIPrefix), artifacthubTag) _, data, err = util.OCIPullLayer(ctx, ref, MetadataLayerMediaType, "", "") + if errors.Is(err, util.ErrArtifactNotFound) || errors.Is(err, util.ErrLayerNotFound) { + err = ErrMetadataNotFound + } } else { // Remote HTTP url / local file path for _, extension := range []string{".yml", ".yaml"} { diff --git a/internal/tracker/source/helm/helm.go b/internal/tracker/source/helm/helm.go index 15363f3f..b9266722 100644 --- a/internal/tracker/source/helm/helm.go +++ b/internal/tracker/source/helm/helm.go @@ -319,6 +319,9 @@ func (s *TrackerSource) chartHasProvenanceFile(chartURL *url.URL) (bool, error) s.i.Repository.AuthPass, ) if err != nil { + if errors.Is(err, util.ErrLayerNotFound) { + return false, nil + } return false, fmt.Errorf("error pulling provenance layer: %w", err) } default: diff --git a/internal/util/oci.go b/internal/util/oci.go index f4569307..ac2e0f12 100644 --- a/internal/util/oci.go +++ b/internal/util/oci.go @@ -3,6 +3,7 @@ package util import ( "context" "errors" + "strings" "github.com/containerd/containerd/remotes/docker" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -12,13 +13,17 @@ import ( ) var ( + // ErrArtifactNotFound indicates that the requested artifact was not found + // in the registry. + ErrArtifactNotFound = errors.New("artifact not found") + // ErrLayerNotFound indicates that the requested layer was not found in the - // OCI image provided. + // OCI artifact provided. ErrLayerNotFound = errors.New("layer not found") ) // OCIPullLayer pulls the first layer of the media type provided from the OCI -// image at the given reference. +// artifact at the given reference. func OCIPullLayer( ctx context.Context, ref, @@ -45,6 +50,9 @@ func OCIPullLayer( oras.WithAllowedMediaTypes([]string{mediaType}), ) if err != nil { + if strings.HasSuffix(err.Error(), "not found") { // TODO: https://github.com/oras-project/oras-go/blob/a3ccc872651aac656c04c9a231423161f98e2f64/pkg/content/multireader.go#L55 + err = ErrArtifactNotFound + } return ocispec.Descriptor{}, nil, err }