diff --git a/pkg/extensions/search/cve/pagination.go b/pkg/extensions/search/cve/pagination.go index db2543f3d..07e4896b0 100644 --- a/pkg/extensions/search/cve/pagination.go +++ b/pkg/extensions/search/cve/pagination.go @@ -1,10 +1,9 @@ package cveinfo import ( + "fmt" "sort" - "github.com/pkg/errors" - zerr "zotregistry.io/zot/errors" cvemodel "zotregistry.io/zot/pkg/extensions/search/cve/model" ) @@ -75,7 +74,7 @@ func NewCvePageFinder(limit, offset int, sortBy SortCriteria, cveInfo CveInfo) ( } if _, found := SortFunctions()[sortBy]; !found { - return nil, errors.Wrapf(zerr.ErrSortCriteriaNotSupported, "sorting CVEs by '%s' is not supported", sortBy) + return nil, fmt.Errorf("sorting CVEs by '%s' is not supported %w", sortBy, zerr.ErrSortCriteriaNotSupported) } return &CvePageFinder{ diff --git a/pkg/extensions/search/cve/trivy/scanner.go b/pkg/extensions/search/cve/trivy/scanner.go index cf59c5c70..2d46d183c 100644 --- a/pkg/extensions/search/cve/trivy/scanner.go +++ b/pkg/extensions/search/cve/trivy/scanner.go @@ -3,6 +3,7 @@ package trivy import ( "context" "encoding/json" + "fmt" "path" "sync" @@ -14,7 +15,6 @@ import ( regTypes "github.com/google/go-containerregistry/pkg/v1/types" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" zerr "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/extensions/search/common" @@ -197,14 +197,14 @@ func (scanner Scanner) IsImageFormatScannable(repo, tag string) (bool, error) { case ispec.MediaTypeImageManifest: ok, err := scanner.isManifestScanable(imageDescriptor) if err != nil { - return ok, errors.Wrapf(err, "image '%s'", image) + return ok, fmt.Errorf("image '%s' %w", image, err) } return ok, nil case ispec.MediaTypeImageIndex: ok, err := scanner.isIndexScanable(imageDescriptor) if err != nil { - return ok, errors.Wrapf(err, "image '%s'", image) + return ok, fmt.Errorf("image '%s' %w", image, err) } return ok, nil diff --git a/pkg/extensions/search/resolver.go b/pkg/extensions/search/resolver.go index 034d80b03..d03358987 100644 --- a/pkg/extensions/search/resolver.go +++ b/pkg/extensions/search/resolver.go @@ -7,6 +7,7 @@ package search import ( "context" "encoding/json" + "errors" "fmt" "sort" "strings" @@ -14,7 +15,6 @@ import ( "github.com/99designs/gqlgen/graphql" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" "github.com/vektah/gqlparser/v2/gqlerror" zerr "zotregistry.io/zot/errors" @@ -890,9 +890,8 @@ func validateGlobalSearchInput(query string, filter *gql_generated.Filter, requestedPage *gql_generated.PageInput, ) error { if len(query) > querySizeLimit { - format := "global-search: max string size limit exeeded for query parameter. max=%d current=%d" - - return errors.Wrapf(zerr.ErrInvalidRequestParams, format, querySizeLimit, len(query)) + return fmt.Errorf("global-search: max string size limit exeeded for query parameter. max=%d current=%d %w", + querySizeLimit, len(query), zerr.ErrInvalidRequestParams) } err := checkFilter(filter) @@ -915,17 +914,15 @@ func checkFilter(filter *gql_generated.Filter) error { for _, arch := range filter.Arch { if len(*arch) > querySizeLimit { - format := "global-search: max string size limit exeeded for arch parameter. max=%d current=%d" - - return errors.Wrapf(zerr.ErrInvalidRequestParams, format, querySizeLimit, len(*arch)) + return fmt.Errorf("global-search: max string size limit exeeded for arch parameter. max=%d current=%d %w", + querySizeLimit, len(*arch), zerr.ErrInvalidRequestParams) } } for _, osSys := range filter.Os { if len(*osSys) > querySizeLimit { - format := "global-search: max string size limit exeeded for os parameter. max=%d current=%d" - - return errors.Wrapf(zerr.ErrInvalidRequestParams, format, querySizeLimit, len(*osSys)) + return fmt.Errorf("global-search: max string size limit exeeded for os parameter. max=%d current=%d %w", + querySizeLimit, len(*osSys), zerr.ErrInvalidRequestParams) } } @@ -938,15 +935,13 @@ func checkRequestedPage(requestedPage *gql_generated.PageInput) error { } if requestedPage.Limit != nil && *requestedPage.Limit < 0 { - format := "global-search: requested page limit parameter can't be negative" - - return errors.Wrap(zerr.ErrInvalidRequestParams, format) + return fmt.Errorf("global-search: requested page limit parameter can't be negative %w", + zerr.ErrInvalidRequestParams) } if requestedPage.Offset != nil && *requestedPage.Offset < 0 { - format := "global-search: requested page offset parameter can't be negative" - - return errors.Wrap(zerr.ErrInvalidRequestParams, format) + return fmt.Errorf("global-search: requested page offset parameter can't be negative %w", + zerr.ErrInvalidRequestParams) } return nil @@ -1041,8 +1036,8 @@ func expandedRepoInfo(ctx context.Context, repo string, repoDB repodb.RepoDB, cv manifestMeta, err := repoDB.GetManifestMeta(repo, godigest.Digest(digest)) if err != nil { - graphql.AddError(ctx, errors.Wrapf(err, - "resolver: failed to get manifest meta for image %s:%s with manifest digest %s", repo, tag, digest)) + graphql.AddError(ctx, fmt.Errorf("resolver: failed to get manifest meta for image %s:%s with manifest digest %s %w", + repo, tag, digest, err)) continue } @@ -1057,8 +1052,8 @@ func expandedRepoInfo(ctx context.Context, repo string, repoDB repodb.RepoDB, cv indexData, err := repoDB.GetIndexData(godigest.Digest(digest)) if err != nil { - graphql.AddError(ctx, errors.Wrapf(err, - "resolver: failed to get manifest meta for image %s:%s with manifest digest %s", repo, tag, digest)) + graphql.AddError(ctx, fmt.Errorf("resolver: failed to get manifest meta for image %s:%s with manifest digest %s %w", + repo, tag, digest, err)) continue } @@ -1067,8 +1062,8 @@ func expandedRepoInfo(ctx context.Context, repo string, repoDB repodb.RepoDB, cv err = json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { - graphql.AddError(ctx, errors.Wrapf(err, - "resolver: failed to unmarshal index content for image %s:%s with digest %s", repo, tag, digest)) + graphql.AddError(ctx, fmt.Errorf("resolver: failed to unmarshal index content for image %s:%s with digest %s %w", + repo, tag, digest, err)) continue } @@ -1078,9 +1073,9 @@ func expandedRepoInfo(ctx context.Context, repo string, repoDB repodb.RepoDB, cv for _, descriptor := range indexContent.Manifests { manifestMeta, err := repoDB.GetManifestMeta(repo, descriptor.Digest) if err != nil { - graphql.AddError(ctx, errors.Wrapf(err, - "resolver: failed to get manifest meta with digest '%s' for multiarch image %s:%s", - digest, repo, tag), + graphql.AddError(ctx, + fmt.Errorf("resolver: failed to get manifest meta with digest '%s' for multiarch image %s:%s %w", + digest, repo, tag, err), ) errorOccured = true @@ -1200,8 +1195,8 @@ func getReferrers(repoDB repodb.RepoDB, repo string, referredDigest string, arti if err := refDigest.Validate(); err != nil { log.Error().Err(err).Msgf("graphql: bad digest string from request '%s'", referredDigest) - return []*gql_generated.Referrer{}, errors.Wrapf(err, "graphql: bad digest string from request '%s'", - referredDigest) + return []*gql_generated.Referrer{}, fmt.Errorf("graphql: bad digest string from request '%s' %w", + referredDigest, err) } referrers, err := repoDB.GetFilteredReferrersInfo(repo, refDigest, artifactTypes) diff --git a/pkg/extensions/sync/sync_test.go b/pkg/extensions/sync/sync_test.go index 2e04864a3..a51ef4f05 100644 --- a/pkg/extensions/sync/sync_test.go +++ b/pkg/extensions/sync/sync_test.go @@ -25,7 +25,6 @@ import ( godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1" - perr "github.com/pkg/errors" "github.com/sigstore/cosign/cmd/cosign/cli/generate" "github.com/sigstore/cosign/cmd/cosign/cli/options" "github.com/sigstore/cosign/cmd/cosign/cli/sign" @@ -5284,7 +5283,7 @@ func pushRepo(url, repoName string) godigest.Digest { } if resp.StatusCode() != http.StatusAccepted { - panic(perr.Wrapf(errBadStatus, "invalid status code: %d", resp.StatusCode())) + panic(fmt.Errorf("invalid status code: %d %w", resp.StatusCode(), errBadStatus)) } loc = test.Location(url, resp) @@ -5302,7 +5301,7 @@ func pushRepo(url, repoName string) godigest.Digest { } if resp.StatusCode() != http.StatusCreated { - panic(perr.Wrapf(errBadStatus, "invalid status code: %d", resp.StatusCode())) + panic(fmt.Errorf("invalid status code: %d %w", resp.StatusCode(), errBadStatus)) } // create a manifest @@ -5437,7 +5436,7 @@ func pushBlob(url string, repoName string, buf []byte) godigest.Digest { } if resp.StatusCode() != http.StatusAccepted { - panic(perr.Wrapf(errBadStatus, "invalid status code: %d", resp.StatusCode())) + panic(fmt.Errorf("invalid status code: %d %w", resp.StatusCode(), errBadStatus)) } loc := test.Location(url, resp) @@ -5456,7 +5455,7 @@ func pushBlob(url string, repoName string, buf []byte) godigest.Digest { } if resp.StatusCode() != http.StatusCreated { - panic(perr.Wrapf(errBadStatus, "invalid status code: %d", resp.StatusCode())) + panic(fmt.Errorf("invalid status code: %d %w", resp.StatusCode(), errBadStatus)) } return digest diff --git a/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go b/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go index 7be7763ab..782c0ce2e 100644 --- a/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go +++ b/pkg/meta/repodb/boltdb-wrapper/boltdb_wrapper.go @@ -3,6 +3,7 @@ package bolt import ( "context" "encoding/json" + "fmt" "os" "path" "strings" @@ -10,7 +11,6 @@ import ( godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" "github.com/rs/zerolog" bolt "go.etcd.io/bbolt" @@ -90,12 +90,12 @@ func (bdw *DBWrapper) SetManifestData(manifestDigest godigest.Digest, manifestDa mdBlob, err := json.Marshal(manifestData) if err != nil { - return errors.Wrapf(err, "repodb: error while calculating blob for manifest with digest %s", manifestDigest) + return fmt.Errorf("repodb: error while calculating blob for manifest with digest %s %w", manifestDigest, err) } err = buck.Put([]byte(manifestDigest), mdBlob) if err != nil { - return errors.Wrapf(err, "repodb: error while setting manifest data with for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while setting manifest data with for digest %s %w", manifestDigest, err) } return nil @@ -118,7 +118,7 @@ func (bdw *DBWrapper) GetManifestData(manifestDigest godigest.Digest) (repodb.Ma err := json.Unmarshal(mdBlob, &manifestData) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling manifest meta for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while unmashaling manifest meta for digest %s %w", manifestDigest, err) } return nil @@ -154,19 +154,19 @@ func (bdw *DBWrapper) SetManifestMeta(repo string, manifestDigest godigest.Diges ConfigBlob: manifestMeta.ConfigBlob, }) if err != nil { - return errors.Wrapf(err, "repodb: error while calculating blob for manifest with digest %s", manifestDigest) + return fmt.Errorf("repodb: error while calculating blob for manifest with digest %s %w", manifestDigest, err) } err = dataBuck.Put([]byte(manifestDigest), mdBlob) if err != nil { - return errors.Wrapf(err, "repodb: error while setting manifest meta with for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while setting manifest meta with for digest %s %w", manifestDigest, err) } updatedRepoMeta := common.UpdateManifestMeta(repoMeta, manifestDigest, manifestMeta) updatedRepoMetaBlob, err := json.Marshal(updatedRepoMeta) if err != nil { - return errors.Wrapf(err, "repodb: error while calculating blob for updated repo meta '%s'", repo) + return fmt.Errorf("repodb: error while calculating blob for updated repo meta '%s' %w", repo, err) } return repoBuck.Put([]byte(repo), updatedRepoMetaBlob) @@ -192,7 +192,7 @@ func (bdw *DBWrapper) GetManifestMeta(repo string, manifestDigest godigest.Diges err := json.Unmarshal(mdBlob, &manifestData) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling manifest meta for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while unmashaling manifest meta for digest %s %w", manifestDigest, err) } var repoMeta repodb.RepoMetadata @@ -201,7 +201,7 @@ func (bdw *DBWrapper) GetManifestMeta(repo string, manifestDigest godigest.Diges if len(repoMetaBlob) > 0 { err = json.Unmarshal(repoMetaBlob, &repoMeta) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling manifest meta for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while unmashaling manifest meta for digest %s %w", manifestDigest, err) } } @@ -228,12 +228,12 @@ func (bdw *DBWrapper) SetIndexData(indexDigest godigest.Digest, indexMetadata re imBlob, err := json.Marshal(indexMetadata) if err != nil { - return errors.Wrapf(err, "repodb: error while calculating blob for manifest with digest %s", indexDigest) + return fmt.Errorf("repodb: error while calculating blob for manifest with digest %s %w", indexDigest, err) } err = buck.Put([]byte(indexDigest), imBlob) if err != nil { - return errors.Wrapf(err, "repodb: error while setting manifest meta with for digest %s", indexDigest) + return fmt.Errorf("repodb: error while setting manifest meta with for digest %s %w", indexDigest, err) } return nil @@ -256,7 +256,7 @@ func (bdw *DBWrapper) GetIndexData(indexDigest godigest.Digest) (repodb.IndexDat err := json.Unmarshal(mmBlob, &indexMetadata) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling manifest meta for digest %s", indexDigest) + return fmt.Errorf("repodb: error while unmashaling manifest meta for digest %s %w", indexDigest, err) } return nil @@ -271,12 +271,12 @@ func (bdw DBWrapper) SetArtifactData(artifactDigest godigest.Digest, artifactDat imBlob, err := json.Marshal(artifactData) if err != nil { - return errors.Wrapf(err, "repodb: error while calculating blob for artifact with digest %s", artifactDigest) + return fmt.Errorf("repodb: error while calculating blob for artifact with digest %s %w", artifactDigest, err) } err = buck.Put([]byte(artifactDigest), imBlob) if err != nil { - return errors.Wrapf(err, "repodb: error while setting artifact blob for digest %s", artifactDigest) + return fmt.Errorf("repodb: error while setting artifact blob for digest %s %w", artifactDigest, err) } return nil @@ -299,7 +299,7 @@ func (bdw DBWrapper) GetArtifactData(artifactDigest godigest.Digest) (repodb.Art err := json.Unmarshal(blob, &artifactData) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling artifact data for digest %s", artifactDigest) + return fmt.Errorf("repodb: error while unmashaling artifact data for digest %s %w", artifactDigest, err) } return nil @@ -1018,14 +1018,14 @@ func (bdw *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter manifestMeta, err := fetchManifestMetaWithCheck(repoMeta, manifestDigest, manifestMetadataMap, manifestBuck) if err != nil { - return errors.Wrapf(err, "repodb: error fetching manifest meta for manifest with digest %s", - manifestDigest) + return fmt.Errorf("repodb: error fetching manifest meta for manifest with digest %s %w", + manifestDigest, err) } manifestFilterData, err := collectImageManifestFilterData(manifestDigest, repoMeta, manifestMeta) if err != nil { - return errors.Wrapf(err, "repodb: error collecting filter data for manifest with digest %s", - manifestDigest) + return fmt.Errorf("repodb: error collecting filter data for manifest with digest %s %w", + manifestDigest, err) } repoDownloads += manifestFilterData.DownloadCount @@ -1052,23 +1052,24 @@ func (bdw *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter indexData, err := fetchIndexDataWithCheck(indexDigest, indexDataMap, indexBuck) if err != nil { - return errors.Wrapf(err, "repodb: error fetching index data for index with digest %s", - indexDigest) + return fmt.Errorf("repodb: error fetching index data for index with digest %s %w", + indexDigest, err) } var indexContent ispec.Index err = json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling index content for %s:%s", repoName, tag) + return fmt.Errorf("repodb: error while unmashaling index content for %s:%s %w", + repoName, tag, err) } // this also updates manifestMetadataMap imageFilterData, err := collectImageIndexFilterInfo(indexDigest, repoMeta, indexData, manifestMetadataMap, manifestBuck) if err != nil { - return errors.Wrapf(err, "repodb: error collecting filter data for index with digest %s", - indexDigest) + return fmt.Errorf("repodb: error collecting filter data for index with digest %s %w", + indexDigest, err) } for _, arch := range imageFilterData.ArchList { @@ -1164,8 +1165,8 @@ func fetchManifestMetaWithCheck(repoMeta repodb.RepoMetadata, manifestDigest str err := json.Unmarshal(manifestDataBlob, &manifestData) if err != nil { - return repodb.ManifestMetadata{}, errors.Wrapf(err, - "repodb: error while unmarshaling manifest metadata for digest %s", manifestDigest) + return repodb.ManifestMetadata{}, fmt.Errorf("repodb: error while unmarshaling manifest metadata for digest %s %w", + manifestDigest, err) } manifestMeta = NewManifestMetadata(manifestDigest, repoMeta, manifestData) @@ -1193,7 +1194,7 @@ func fetchIndexDataWithCheck(indexDigest string, indexDataMap map[string]repodb. err := json.Unmarshal(indexDataBlob, &indexData) if err != nil { return repodb.IndexData{}, - errors.Wrapf(err, "repodb: error while unmashaling index data for digest %s", indexDigest) + fmt.Errorf("repodb: error while unmashaling index data for digest %s %w", indexDigest, err) } } @@ -1213,7 +1214,7 @@ func collectImageManifestFilterData(digest string, repoMeta repodb.RepoMetadata, err := json.Unmarshal(manifestMeta.ConfigBlob, &configContent) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "repodb: error while unmarshaling config content") + fmt.Errorf("repodb: error while unmarshaling config content %w", err) } if configContent.OS != "" { @@ -1242,7 +1243,7 @@ func collectImageIndexFilterInfo(indexDigest string, repoMeta repodb.RepoMetadat err := json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "repodb: error while unmarshaling index content for digest %s", indexDigest) + fmt.Errorf("repodb: error while unmarshaling index content for digest %s %w", indexDigest, err) } var ( @@ -1259,14 +1260,14 @@ func collectImageIndexFilterInfo(indexDigest string, repoMeta repodb.RepoMetadat manifestMetadataMap, manifestBuck) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } manifestFilterData, err := collectImageManifestFilterData(manifestDigest.String(), repoMeta, manifestMeta) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } indexOsList = append(indexOsList, manifestFilterData.OsList...) @@ -1360,7 +1361,7 @@ func (bdw *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, manifestMeta, err := fetchManifestMetaWithCheck(repoMeta, manifestDigest, manifestMetadataMap, manifestBuck) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling manifest metadata for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while unmashaling manifest metadata for digest %s %w", manifestDigest, err) } if !filter(repoMeta, manifestMeta) { @@ -1375,14 +1376,14 @@ func (bdw *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, indexData, err := fetchIndexDataWithCheck(indexDigest, indexDataMap, indexBuck) if err != nil { - return errors.Wrapf(err, "repodb: error while getting index data for digest %s", indexDigest) + return fmt.Errorf("repodb: error while getting index data for digest %s %w", indexDigest, err) } var indexContent ispec.Index err = json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { - return errors.Wrapf(err, "repodb: error while unmashaling index content for digest %s", indexDigest) + return fmt.Errorf("repodb: error while unmashaling index content for digest %s %w", indexDigest, err) } manifestHasBeenMatched := false @@ -1392,7 +1393,7 @@ func (bdw *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, manifestMeta, err := fetchManifestMetaWithCheck(repoMeta, manifestDigest, manifestMetadataMap, manifestBuck) if err != nil { - return errors.Wrapf(err, "repodb: error while getting manifest data for digest %s", manifestDigest) + return fmt.Errorf("repodb: error while getting manifest data for digest %s %w", manifestDigest, err) } manifestMetadataMap[manifestDigest] = manifestMeta @@ -1490,7 +1491,7 @@ func (bdw *DBWrapper) SearchTags(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, repodb.PageInfo{}, - errors.Wrap(err, "repodb: error while parsing search text, invalid format") + fmt.Errorf("repodb: error while parsing search text, invalid format %w", err) } err = bdw.DB.View(func(tx *bolt.Tx) error { @@ -1531,14 +1532,14 @@ func (bdw *DBWrapper) SearchTags(ctx context.Context, searchText string, filter manifestMeta, err := fetchManifestMetaWithCheck(repoMeta, manifestDigest, manifestMetadataMap, manifestBuck) if err != nil { - return errors.Wrapf(err, "repodb: error fetching manifest meta for manifest with digest %s", - manifestDigest) + return fmt.Errorf("repodb: error fetching manifest meta for manifest with digest %s %w", + manifestDigest, err) } imageFilterData, err := collectImageManifestFilterData(manifestDigest, repoMeta, manifestMeta) if err != nil { - return errors.Wrapf(err, "repodb: error collecting filter data for manifest with digest %s", - manifestDigest) + return fmt.Errorf("repodb: error collecting filter data for manifest with digest %s %w", + manifestDigest, err) } if !common.AcceptedByFilter(filter, imageFilterData) { @@ -1553,16 +1554,16 @@ func (bdw *DBWrapper) SearchTags(ctx context.Context, searchText string, filter indexData, err := fetchIndexDataWithCheck(indexDigest, indexDataMap, indexBuck) if err != nil { - return errors.Wrapf(err, "repodb: error fetching index data for index with digest %s", - indexDigest) + return fmt.Errorf("repodb: error fetching index data for index with digest %s %w", + indexDigest, err) } var indexContent ispec.Index err = json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { - return errors.Wrapf(err, "repodb: error collecting filter data for index with digest %s", - indexDigest) + return fmt.Errorf("repodb: error collecting filter data for index with digest %s %w", + indexDigest, err) } manifestHasBeenMatched := false @@ -1572,14 +1573,14 @@ func (bdw *DBWrapper) SearchTags(ctx context.Context, searchText string, filter manifestMeta, err := fetchManifestMetaWithCheck(repoMeta, manifestDigest, manifestMetadataMap, manifestBuck) if err != nil { - return errors.Wrapf(err, "repodb: error fetching from db manifest meta for manifest with digest %s", - manifestDigest) + return fmt.Errorf("repodb: error fetching from db manifest meta for manifest with digest %s %w", + manifestDigest, err) } manifestFilterData, err := collectImageManifestFilterData(manifestDigest, repoMeta, manifestMeta) if err != nil { - return errors.Wrapf(err, "repodb: error collecting filter data for manifest with digest %s", - manifestDigest) + return fmt.Errorf("repodb: error collecting filter data for manifest with digest %s %w", + manifestDigest, err) } manifestMetadataMap[manifestDigest] = manifestMeta @@ -1664,11 +1665,11 @@ func (bdw *DBWrapper) PatchDB() error { return nil }) if err != nil { - return errors.Wrapf(err, "patching the database failed, can't read db version") + return fmt.Errorf("patching the database failed, can't read db version %w", err) } if version.GetVersionIndex(DBVersion) == -1 { - return errors.New("DB has broken format, no version found") + return fmt.Errorf("DB has broken format, no version found %w", err) } for patchIndex, patch := range bdw.Patches { diff --git a/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go b/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go index e91f90d85..913e0fe7b 100644 --- a/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go +++ b/pkg/meta/repodb/dynamodb-wrapper/dynamo_wrapper.go @@ -3,6 +3,8 @@ package dynamo import ( "context" "encoding/json" + "errors" + "fmt" "os" "strings" "time" @@ -14,7 +16,6 @@ import ( "github.com/aws/aws-sdk-go-v2/service/dynamodb/types" godigest "github.com/opencontainers/go-digest" ispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" "github.com/rs/zerolog" zerr "zotregistry.io/zot/errors" @@ -27,6 +28,8 @@ import ( localCtx "zotregistry.io/zot/pkg/requestcontext" ) +var errRepodb = errors.New("repodb: error while constructing manifest meta") + type DBWrapper struct { Client *dynamodb.Client RepoMetaTablename string @@ -196,8 +199,7 @@ func (dwr *DBWrapper) GetManifestMeta(repo string, manifestDigest godigest.Diges } return repodb.ManifestMetadata{}, - errors.Wrapf(err, "error while constructing manifest meta for manifest '%s' from repo '%s'", - manifestDigest, repo) + fmt.Errorf("%w for manifest '%s' from repo '%s'", errRepodb, manifestDigest, repo) } repoMeta, err := dwr.GetRepoMeta(repo) @@ -207,8 +209,7 @@ func (dwr *DBWrapper) GetManifestMeta(repo string, manifestDigest godigest.Diges } return repodb.ManifestMetadata{}, - errors.Wrapf(err, "error while constructing manifest meta for manifest '%s' from repo '%s'", - manifestDigest, repo) + fmt.Errorf("%w for manifest '%s' from repo '%s'", errRepodb, manifestDigest, repo) } manifestMetadata := repodb.ManifestMetadata{} @@ -903,14 +904,14 @@ func (dwr *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } manifestFilterData, err := collectImageManifestFilterData(manifestDigest, repoMeta, manifestMeta) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } repoDownloads += manifestFilterData.DownloadCount @@ -940,7 +941,7 @@ func (dwr *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } // this also updates manifestMetadataMap @@ -949,7 +950,7 @@ func (dwr *DBWrapper) SearchRepos(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } for _, arch := range imageFilterData.ArchList { @@ -1032,8 +1033,7 @@ func collectImageManifestFilterData(digest string, repoMeta repodb.RepoMetadata, err := json.Unmarshal(manifestMeta.ConfigBlob, &configContent) if err != nil { - return repodb.FilterData{}, - errors.Wrapf(err, "repodb: error while unmarshaling config content") + return repodb.FilterData{}, fmt.Errorf("repodb: error while unmarshaling config content %w", err) } if configContent.OS != "" { @@ -1066,7 +1066,7 @@ func (dwr *DBWrapper) fetchIndexDataWithCheck(indexDigest string, indexDataMap m indexData, err = dwr.GetIndexData(godigest.Digest(indexDigest)) //nolint:contextcheck if err != nil { return repodb.IndexData{}, - errors.Wrapf(err, "repodb: error while unmarshaling index data for digest %s", indexDigest) + fmt.Errorf("repodb: error while unmarshaling index data for digest %s \n%w", indexDigest, err) } } @@ -1081,7 +1081,7 @@ func (dwr *DBWrapper) collectImageIndexFilterInfo(indexDigest string, repoMeta r err := json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "repodb: error while unmarshaling index content for digest %s", indexDigest) + fmt.Errorf("repodb: error while unmarshaling index content for digest %s %w", indexDigest, err) } var ( @@ -1098,14 +1098,14 @@ func (dwr *DBWrapper) collectImageIndexFilterInfo(indexDigest string, repoMeta r manifestMetadataMap) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } manifestFilterData, err := collectImageManifestFilterData(manifestDigest.String(), repoMeta, manifestMeta) if err != nil { return repodb.FilterData{}, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } indexOsList = append(indexOsList, manifestFilterData.OsList...) @@ -1183,7 +1183,7 @@ func (dwr *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "repodb: error while unmashaling manifest metadata for digest %s", manifestDigest) + fmt.Errorf("repodb: error while unmashaling manifest metadata for digest %s \n%w", manifestDigest, err) } if !filter(repoMeta, manifestMeta) { @@ -1200,7 +1200,7 @@ func (dwr *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "repodb: error while getting index data for digest %s", indexDigest) + fmt.Errorf("repodb: error while getting index data for digest %s %w", indexDigest, err) } var indexContent ispec.Index @@ -1209,7 +1209,7 @@ func (dwr *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "repodb: error while unmashaling index content for digest %s", indexDigest) + fmt.Errorf("repodb: error while unmashaling index content for digest %s %w", indexDigest, err) } manifestHasBeenMatched := false @@ -1222,7 +1222,7 @@ func (dwr *DBWrapper) FilterTags(ctx context.Context, filter repodb.FilterFunc, if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "repodb: error while getting manifest data for digest %s", manifestDigest) + fmt.Errorf("%w repodb: error while getting manifest data for digest %s", err, manifestDigest) } manifestMetadataMap[manifestDigest] = manifestMeta @@ -1290,7 +1290,7 @@ func (dwr *DBWrapper) SearchTags(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrap(err, "repodb: error while parsing search text, invalid format") + fmt.Errorf("repodb: error while parsing search text, invalid format %w", err) } repoMetaAttribute, err := repoMetaAttributeIterator.First(ctx) @@ -1333,14 +1333,14 @@ func (dwr *DBWrapper) SearchTags(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "repodb: error while unmashaling manifest metadata for digest %s", descriptor.Digest) + fmt.Errorf("repodb: error while unmashaling manifest metadata for digest %s %w", descriptor.Digest, err) } imageFilterData, err := collectImageManifestFilterData(manifestDigest, repoMeta, manifestMeta) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } if !common.AcceptedByFilter(filter, imageFilterData) { @@ -1357,7 +1357,7 @@ func (dwr *DBWrapper) SearchTags(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } var indexContent ispec.Index @@ -1366,7 +1366,7 @@ func (dwr *DBWrapper) SearchTags(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "repodb: error while unmashaling index content for digest %s", indexDigest) + fmt.Errorf("repodb: error while unmashaling index content for digest %s %w", indexDigest, err) } manifestHasBeenMatched := false @@ -1379,14 +1379,14 @@ func (dwr *DBWrapper) SearchTags(ctx context.Context, searchText string, filter if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } manifestFilterData, err := collectImageManifestFilterData(manifestDigest, repoMeta, manifestMeta) if err != nil { return []repodb.RepoMetadata{}, map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, pageInfo, - errors.Wrapf(err, "") + fmt.Errorf("%w", err) } manifestMetadataMap[manifestDigest] = manifestMeta @@ -1453,7 +1453,7 @@ func filterFoundData(foundRepos []repodb.RepoMetadata, manifestMetadataMap map[s err := json.Unmarshal(indexData.IndexBlob, &indexContent) if err != nil { return map[string]repodb.ManifestMetadata{}, map[string]repodb.IndexData{}, - errors.Wrapf(err, "repodb: error while getting manifest data for digest %s", descriptor.Digest) + fmt.Errorf("repodb: error while getting manifest data for digest %s %w", descriptor.Digest, err) } for _, manifestDescriptor := range indexContent.Manifests { @@ -1474,11 +1474,11 @@ func filterFoundData(foundRepos []repodb.RepoMetadata, manifestMetadataMap map[s func (dwr *DBWrapper) PatchDB() error { DBVersion, err := dwr.getDBVersion() if err != nil { - return errors.Wrapf(err, "patching dynamo failed, error retrieving database version") + return fmt.Errorf("patching dynamo failed, error retrieving database version %w", err) } if version.GetVersionIndex(DBVersion) == -1 { - return errors.New("DB has broken format, no version found") + return fmt.Errorf("DB has broken format, no version found %w", err) } for patchIndex, patch := range dwr.Patches { diff --git a/pkg/meta/repodb/pagination.go b/pkg/meta/repodb/pagination.go index 54ab0ad5f..30c2fd9e7 100644 --- a/pkg/meta/repodb/pagination.go +++ b/pkg/meta/repodb/pagination.go @@ -1,10 +1,9 @@ package repodb import ( + "fmt" "sort" - "github.com/pkg/errors" - zerr "zotregistry.io/zot/errors" ) @@ -39,7 +38,8 @@ func NewBaseRepoPageFinder(limit, offset int, sortBy SortCriteria) (*RepoPageFin } if _, found := SortFunctions()[sortBy]; !found { - return nil, errors.Wrapf(zerr.ErrSortCriteriaNotSupported, "sorting repos by '%s' is not supported", sortBy) + return nil, fmt.Errorf("sorting repos by '%s' is not supported %w", + sortBy, zerr.ErrSortCriteriaNotSupported) } return &RepoPageFinder{ @@ -122,7 +122,8 @@ func NewBaseImagePageFinder(limit, offset int, sortBy SortCriteria) (*ImagePageF } if _, found := SortFunctions()[sortBy]; !found { - return nil, errors.Wrapf(zerr.ErrSortCriteriaNotSupported, "sorting repos by '%s' is not supported", sortBy) + return nil, fmt.Errorf("sorting repos by '%s' is not supported %w", + sortBy, zerr.ErrSortCriteriaNotSupported) } return &ImagePageFinder{ diff --git a/pkg/meta/repodb/update/update.go b/pkg/meta/repodb/update/update.go index d059aad23..4b89e5fb5 100644 --- a/pkg/meta/repodb/update/update.go +++ b/pkg/meta/repodb/update/update.go @@ -1,8 +1,9 @@ package update import ( + "errors" + godigest "github.com/opencontainers/go-digest" - "github.com/pkg/errors" zerr "zotregistry.io/zot/errors" "zotregistry.io/zot/pkg/log"