-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Fix linting issues in preparation of Go and GolangCI-lint update #48359
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
Conversation
layer/layer.go
Outdated
if parent == "" { | ||
return createChainIDFromParent(ChainID(dgsts[0]), dgsts[1:]...) | ||
return createChainIDFromParent(ChainID(dgsts[0]), dgsts[1:]...) //nolint:gosec // FIXME(thaJeztah): ignore G602: slice index out of range, which is a false positive | ||
} | ||
// H = "H(n-1) SHA256(n)" | ||
dgst := digest.FromBytes([]byte(string(parent) + " " + string(dgsts[0]))) | ||
return createChainIDFromParent(ChainID(dgst), dgsts[1:]...) | ||
dgst := digest.FromBytes([]byte(string(parent) + " " + string(dgsts[0]))) //nolint:gosec // FIXME(thaJeztah): ignore G602: slice index out of range, which is a false positive | ||
return createChainIDFromParent(ChainID(dgst), dgsts[1:]...) //nolint:gosec // FIXME(thaJeztah): ignore G602: slice index out of range, which is a false positive | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to create a minimal reproducer for this one, but for some reason GolangCI only picked up this case, but not when trying to write a more minimal one. I'll give it another try to see if I can report this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The printf govet lints are all legitimate code bugs. Don't ignore them!
@@ -40,7 +40,7 @@ func initIPAMDrivers(r ipamapi.Registerer, netConfig *networkallocator.Config) e | |||
} | |||
|
|||
if len(addressPool) > 0 { | |||
log.G(context.TODO()).Infof("Swarm initialized global default address pool to: " + str.String()) | |||
log.G(context.TODO()).Info("Swarm initialized global default address pool to: " + str.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively:
log.G(context.TODO()).Info("Swarm initialized global default address pool to: " + str.String()) | |
log.G(context.TODO()).Infof("Swarm initialized global default address pool to: %v", str.String()) |
_, _ = fmt.Fprint(conn, "HTTP/1.1 101 UPGRADED\r\nContent-Type: "+contentType+"\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n") | ||
} else { | ||
fmt.Fprintf(conn, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") | ||
_, _ = fmt.Fprint(conn, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really be ignoring errors encountered while writing to the socket? If the connection has e.g. been reset by the remote end, any attempt to continue handling the request is just wasting cycles.
And on the topic of ignoring write errors, see line 977.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look at this in a follow-up; I had a quick peek at how this code is used, and saw some other parts that I want to have a look at.
Failure looks like it may be related to changes deployed to docker hub w.r.t. search. I tried both on master and this PR, and both fail;
OK confirmed; something odd with limits. I’m able to reproduce with just curl and jq;
w.r.t. “expected to be more than 100 results for
|
59886ec
to
573af21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@corhere updated; I took most of your suggestions; I still want to look at the error-handling in a follow-up
if len(errors) > 0 { | ||
return fmt.Errorf(strings.Join(errors, "\n")) | ||
if len(errs) > 0 { | ||
return errors.New(strings.Join(errs, "\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like an ideal candidate for errors.Join
(it even formats the same!) but that'd be out of scope for this PR. Follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh; yup, I was looking at exactly that! 👍
// FIXME(thaJeztah): we should not ignore errors here; see https://github.com/moby/moby/pull/48359#discussion_r1725562802 | ||
_, _ = fmt.Fprintf(conn, "HTTP/1.1 101 UPGRADED\r\nContent-Type: %v\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n", contentType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicitly assigning an error-return value to underscore signifies that discarding the error is intentional and correct. That is not the case here, given the need for the FIXME comment. Our linter settings currently exclude the errcheck
rule that complains about implicitly-ignored error returns for printf-family functions so there is no need to appease the linter here and now to get CI to pass. Adding underscore-assignments here does our future selves a disservice as it prevents us from being able to find all the call sites in need of fixes by linting the project without that lint exclusion rule.
This condition was added in 0215a62, which removed pkg/homedir as abstraction, but didn't consider that this test is currently only ran on Unix. integration-cli/docker_cli_run_unix_test.go:254:5: SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck) if runtime.GOOS == "windows" { ^ integration-cli/docker_cli_run_unix_test.go:338:5: SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck) if runtime.GOOS == "windows" { ^ Added a TODO, because this functionality should also be tested on Windows, probably as part of tests in docker/cli instead. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
libnetwork/sandbox_dns_unix_test.go:17:13: SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck) skip.If(t, runtime.GOOS == "windows", "test only works on linux") ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
integration-cli/benchmark_test.go:49:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ integration-cli/benchmark_test.go:62:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ integration-cli/benchmark_test.go:68:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ integration-cli/benchmark_test.go:73:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ integration-cli/benchmark_test.go:78:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ integration-cli/benchmark_test.go:84:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ integration-cli/benchmark_test.go:94:27: printf: non-constant format string in call to fmt.Errorf (govet) chErr <- fmt.Errorf(out) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Also rename some variables that shadowed imports, and fix some unhandled errors. integration-cli/docker_cli_network_unix_test.go:102:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"Error":"failed to add veth pair: `+err.Error()+`"}`) ^ integration-cli/docker_cli_network_unix_test.go:136:18: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"LocalDefaultAddressSpace":"`+lAS+`", "GlobalDefaultAddressSpace": "`+gAS+`"}`) ^ integration-cli/docker_cli_network_unix_test.go:147:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"Error":"Unknown address space in pool request: `+poolRequest.AddressSpace+`"}`) ^ integration-cli/docker_cli_network_unix_test.go:151:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"PoolID":"`+poolID+`", "Pool":"`+pool+`"}`) ^ integration-cli/docker_cli_network_unix_test.go:168:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"Address":"`+gw+`"}`) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Also fix some unhandled errors. integration-cli/docker_cli_swarm_test.go:697:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"Error":"failed to add veth pair: `+err.Error()+`"}`) ^ integration-cli/docker_cli_swarm_test.go:731:18: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"LocalDefaultAddressSpace":"`+lAS+`", "GlobalDefaultAddressSpace": "`+gAS+`"}`) ^ integration-cli/docker_cli_swarm_test.go:742:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"Error":"Unknown address space in pool request: `+poolRequest.AddressSpace+`"}`) ^ integration-cli/docker_cli_swarm_test.go:746:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"PoolID":"`+poolID+`", "Pool":"`+pool+`"}`) ^ integration-cli/docker_cli_swarm_test.go:763:19: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(w, `{"Address":"`+gw+`"}`) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
libnetwork/controller.go:1054:32: printf: non-constant format string in call to github.com/docker/docker/libnetwork/types.NotFoundErrorf (govet) return types.NotFoundErrorf(err.Error()) ^ libnetwork/controller.go:1073:32: printf: non-constant format string in call to github.com/docker/docker/libnetwork/types.NotFoundErrorf (govet) return types.NotFoundErrorf(err.Error()) ^ libnetwork/sandbox_externalkey_unix.go:113:21: printf: non-constant format string in call to fmt.Errorf (govet) return fmt.Errorf(string(buf[0:n])) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
cmd/dockerd/required.go:17:24: printf: non-constant format string in call to github.com/docker/docker/vendor/github.com/pkg/errors.Errorf (govet) return errors.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n")) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
libnetwork/cnmallocator/drivers_ipam.go:43:31: printf: non-constant format string in call to (*github.com/docker/docker/vendor/github.com/sirupsen/logrus.Entry).Infof (govet) log.G(context.TODO()).Infof("Swarm initialized global default address pool to: " + str.String()) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
internal/cleanups/composite_test.go:46:9: printf: non-constant format string in call to (*testing.common).Logf (govet) t.Logf(err.Error()) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This looks to be a false positive; layer/layer.go:202:47: G602: slice index out of range (gosec) return createChainIDFromParent(ChainID(dgsts[0]), dgsts[1:]...) ^ layer/layer.go:205:69: G602: slice index out of range (gosec) dgst := digest.FromBytes([]byte(string(parent) + " " + string(dgsts[0]))) ^ layer/layer.go:206:53: G602: slice bounds out of range (gosec) return createChainIDFromParent(ChainID(dgst), dgsts[1:]...) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
… call (govet) builder/dockerfile/internals_linux.go:38:48: printf: non-constant format string in call to github.com/docker/docker/vendor/github.com/pkg/errors.Wrapf (govet) return idtools.Identity{}, errors.Wrapf(err, "can't find uid for user "+userStr) ^ builder/dockerfile/internals_linux.go:42:48: printf: non-constant format string in call to github.com/docker/docker/vendor/github.com/pkg/errors.Wrapf (govet) return idtools.Identity{}, errors.Wrapf(err, "can't find gid for group "+grpStr) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
volume/testutils/testutils.go:98:26: printf: non-constant format string in call to fmt.Errorf (govet) return nil, fmt.Errorf(opts["error"]) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…vet) libnetwork/drivers/bridge/setup_ip_tables_linux.go:385:23: printf: non-constant format string in call to fmt.Errorf (govet) return fmt.Errorf(msg) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
container/stream/streams.go:111:21: printf: non-constant format string in call to fmt.Errorf (govet) return fmt.Errorf(strings.Join(errors, "\n")) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
api/server/router/container/container_routes.go:943:22: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(conn, "HTTP/1.1 101 UPGRADED\r\nContent-Type: "+contentType+"\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n") ^ api/server/router/image/image_routes.go:144:50: printf: non-constant format string in call to github.com/docker/docker/pkg/streamformatter.FormatStatus (govet) output.Write(streamformatter.FormatStatus("", id.String())) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
api/types/container/hostconfig.go:328:43: printf: non-constant format string in call to fmt.Errorf (govet) return &errInvalidParameter{fmt.Errorf(msg)} ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
daemon/daemon.go:942:21: printf: non-constant format string in call to (*github.com/docker/docker/vendor/github.com/sirupsen/logrus.Entry).Errorf (govet) log.G(ctx).Errorf(err.Error()) ^ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
573af21
to
1ad5b5a
Compare
@corhere updated; let me know if this is what you had in mind for the error-handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
See individual commits for details