From 7b6ae1922d924a38c9234feee9d5036578e52ae9 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 23 Mar 2022 18:57:16 +0100 Subject: [PATCH] lint: fix issues with go 1.18 nolint for strings.Title, we only have ASCII strings and want to capitalize only the first character so no need to worry about unicode also adds our own definition for temporary network error so we can continue to propagate net.Error through the "temporary" status Signed-off-by: CrazyMax --- frontend/dockerfile/instructions/parse.go | 2 +- hack/dockerfiles/lint.Dockerfile | 1 + solver/testutil/cachestorage_testsuite.go | 2 +- util/resolver/retryhandler/retry.go | 15 ++++++++++++++- util/testutil/integration/run.go | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/frontend/dockerfile/instructions/parse.go b/frontend/dockerfile/instructions/parse.go index d3b7326ce2508..a04e9b9d4f482 100644 --- a/frontend/dockerfile/instructions/parse.go +++ b/frontend/dockerfile/instructions/parse.go @@ -725,7 +725,7 @@ func errExactlyOneArgument(command string) error { } func errNoDestinationArgument(command string) error { - return errors.Errorf("%s requires at least two arguments, but only one was provided. Destination could not be determined.", command) + return errors.Errorf("%s requires at least two arguments, but only one was provided. Destination could not be determined", command) } func errBadHeredoc(command string, option string) error { diff --git a/hack/dockerfiles/lint.Dockerfile b/hack/dockerfiles/lint.Dockerfile index 9de6fbfc5b50e..06b8fab905407 100644 --- a/hack/dockerfiles/lint.Dockerfile +++ b/hack/dockerfiles/lint.Dockerfile @@ -1,6 +1,7 @@ # syntax=docker/dockerfile-upstream:master FROM golang:1.18-alpine +ENV GOFLAGS="-buildvcs=false" RUN apk add --no-cache gcc musl-dev yamllint RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.45.0 WORKDIR /go/src/github.com/moby/buildkit diff --git a/solver/testutil/cachestorage_testsuite.go b/solver/testutil/cachestorage_testsuite.go index e883ddd2a6ebb..0c6de331645ff 100644 --- a/solver/testutil/cachestorage_testsuite.go +++ b/solver/testutil/cachestorage_testsuite.go @@ -387,7 +387,7 @@ func testWalkIDsByResult(t *testing.T, st solver.CacheKeyStorage) { func getFunctionName(i interface{}) string { fullname := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() dot := strings.LastIndex(fullname, ".") + 1 - return strings.Title(fullname[dot:]) + return strings.Title(fullname[dot:]) //nolint:staticcheck // SA1019: strings.Title is deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead. } func rootKey(dgst digest.Digest, output solver.Index) digest.Digest { diff --git a/util/resolver/retryhandler/retry.go b/util/resolver/retryhandler/retry.go index 554076b07b41d..9fd0ba113cf9b 100644 --- a/util/resolver/retryhandler/retry.go +++ b/util/resolver/retryhandler/retry.go @@ -60,7 +60,7 @@ func retryError(err error) bool { return true } // catches TLS timeout or other network-related temporary errors - if ne, ok := errors.Cause(err).(net.Error); ok && ne.Temporary() { + if ne, ok := errors.Cause(err).(net.Error); ok && (ne.Timeout() || isTemporaryNetworkError(ne)) { return true } // https://github.com/containerd/containerd/pull/4724 @@ -70,3 +70,16 @@ func retryError(err error) bool { return false } + +// isTemporaryNetworkError returns false unless the error implements +// a Temporary() bool method such as url.Error and net.Error. +// Otherwise, returns the value of the Temporary() method. +func isTemporaryNetworkError(err error) bool { + t, ok := err.(interface { + Temporary() bool + }) + if !ok { + return false + } + return t.Temporary() +} diff --git a/util/testutil/integration/run.go b/util/testutil/integration/run.go index b54b21e773274..3f1b66220eb42 100644 --- a/util/testutil/integration/run.go +++ b/util/testutil/integration/run.go @@ -210,7 +210,7 @@ func Run(t *testing.T, testCases []Test, opt ...TestOpt) { func getFunctionName(i interface{}) string { fullname := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() dot := strings.LastIndex(fullname, ".") + 1 - return strings.Title(fullname[dot:]) + return strings.Title(fullname[dot:]) //nolint:staticcheck // SA1019: strings.Title is deprecated: The rule Title uses for word boundaries does not handle Unicode punctuation properly. Use golang.org/x/text/cases instead. } var localImageCache map[string]map[string]struct{}