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

chore(deps): remove usage of deprecated package pkg/errors #1262

Merged
merged 1 commit into from
Mar 14, 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
5 changes: 2 additions & 3 deletions pkg/extensions/search/cve/pagination.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions pkg/extensions/search/cve/trivy/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package trivy
import (
"context"
"encoding/json"
"fmt"
"path"
"sync"

Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
49 changes: 22 additions & 27 deletions pkg/extensions/search/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package search
import (
"context"
"encoding/json"
"errors"
"fmt"
"sort"
"strings"

"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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions pkg/extensions/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading