From ebc47359ead686b6b9fc62e1102e8e3e73ee7dfd Mon Sep 17 00:00:00 2001 From: Akhil Mohan Date: Wed, 14 Aug 2024 16:01:12 +0530 Subject: [PATCH] use format string when using printf like commands As per https://github.com/golang/go/issues/60529, printf like commands with non-constant format strings and no args give an error in govet Signed-off-by: Akhil Mohan --- core/remotes/docker/fetcher_test.go | 7 ++++--- internal/cri/server/container_checkpoint_linux.go | 2 +- pkg/filters/parser.go | 6 +++--- plugins/services/content/contentserver/contentserver.go | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/remotes/docker/fetcher_test.go b/core/remotes/docker/fetcher_test.go index b9a0f5b87..4a624be47 100644 --- a/core/remotes/docker/fetcher_test.go +++ b/core/remotes/docker/fetcher_test.go @@ -22,6 +22,7 @@ import ( "compress/gzip" "context" "encoding/json" + "errors" "fmt" "io" "math/rand" @@ -290,14 +291,14 @@ func TestDockerFetcherOpen(t *testing.T) { { name: "should return just status if the registry request fails and does not return a docker error", mockedStatus: 500, - mockedErr: fmt.Errorf("Non-docker error"), + mockedErr: errors.New("Non-docker error"), want: nil, wantErr: true, wantPlainError: true, }, { name: "should return StatusRequestTimeout after 5 retries", mockedStatus: http.StatusRequestTimeout, - mockedErr: fmt.Errorf(http.StatusText(http.StatusRequestTimeout)), + mockedErr: errors.New(http.StatusText(http.StatusRequestTimeout)), want: nil, wantErr: true, wantPlainError: true, @@ -305,7 +306,7 @@ func TestDockerFetcherOpen(t *testing.T) { }, { name: "should return StatusTooManyRequests after 5 retries", mockedStatus: http.StatusTooManyRequests, - mockedErr: fmt.Errorf(http.StatusText(http.StatusTooManyRequests)), + mockedErr: errors.New(http.StatusText(http.StatusTooManyRequests)), want: nil, wantErr: true, wantPlainError: true, diff --git a/internal/cri/server/container_checkpoint_linux.go b/internal/cri/server/container_checkpoint_linux.go index 5f8a79e92..baabee348 100644 --- a/internal/cri/server/container_checkpoint_linux.go +++ b/internal/cri/server/container_checkpoint_linux.go @@ -76,7 +76,7 @@ func (c *criService) CheckpointContainer(ctx context.Context, r *runtime.Checkpo podCriuVersion, r.GetContainerId(), ) - log.G(ctx).WithError(err).Errorf(errorMessage) + log.G(ctx).WithError(err).Error(errorMessage) return nil, fmt.Errorf( "%s: %w", errorMessage, diff --git a/pkg/filters/parser.go b/pkg/filters/parser.go index f07fd33bd..e86ed8eb4 100644 --- a/pkg/filters/parser.go +++ b/pkg/filters/parser.go @@ -208,7 +208,7 @@ func (p *parser) field() (string, error) { case tokenQuoted: return p.unquote(pos, s, false) case tokenIllegal: - return "", p.mkerr(pos, p.scanner.err) + return "", p.mkerr(pos, "%s", p.scanner.err) } return "", p.mkerr(pos, "expected field or quoted") @@ -229,7 +229,7 @@ func (p *parser) operator() (operator, error) { return 0, p.mkerr(pos, "unsupported operator %q", s) } case tokenIllegal: - return 0, p.mkerr(pos, p.scanner.err) + return 0, p.mkerr(pos, "%s", p.scanner.err) } return 0, p.mkerr(pos, `expected an operator ("=="|"!="|"~=")`) @@ -244,7 +244,7 @@ func (p *parser) value(allowAltQuotes bool) (string, error) { case tokenQuoted: return p.unquote(pos, s, allowAltQuotes) case tokenIllegal: - return "", p.mkerr(pos, p.scanner.err) + return "", p.mkerr(pos, "%s", p.scanner.err) } return "", p.mkerr(pos, "expected value or quoted") diff --git a/plugins/services/content/contentserver/contentserver.go b/plugins/services/content/contentserver/contentserver.go index e69b5b9f2..b212070d6 100644 --- a/plugins/services/content/contentserver/contentserver.go +++ b/plugins/services/content/contentserver/contentserver.go @@ -133,7 +133,7 @@ func (s *service) Delete(ctx context.Context, req *api.DeleteContentRequest) (*p log.G(ctx).WithField("digest", req.Digest).Debugf("delete content") dg, err := digest.Parse(req.Digest) if err != nil { - return nil, status.Errorf(codes.InvalidArgument, err.Error()) + return nil, status.Error(codes.InvalidArgument, err.Error()) } if err := s.store.Delete(ctx, dg); err != nil {