From 598d40a75da82119ceaa030d6eb61fcc527e252f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 21 Aug 2024 14:59:20 +0200 Subject: [PATCH] integration-cli: use erors.New() instead of fmt.Errorf 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 (cherry picked from commit 2b7a6875548197faf0494fda1029afc15a88e301) Signed-off-by: Andrey Epifanov # Conflicts: # integration-cli/benchmark_test.go --- container/stream/streams.go | 13 +++++++------ integration-cli/benchmark_test.go | 18 +++++++++--------- libnetwork/drivers/bridge/setup_ip_tables.go | 2 +- libnetwork/sandbox_externalkey_unix.go | 3 ++- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/container/stream/streams.go b/container/stream/streams.go index 83e6ded611..0f95333977 100644 --- a/container/stream/streams.go +++ b/container/stream/streams.go @@ -2,6 +2,7 @@ package stream // import "github.com/docker/docker/container/stream" import ( "context" + "errors" "fmt" "io" "strings" @@ -91,24 +92,24 @@ func (c *Config) NewNopInputPipe() { // CloseStreams ensures that the configured streams are properly closed. func (c *Config) CloseStreams() error { - var errors []string + var errs []string if c.stdin != nil { if err := c.stdin.Close(); err != nil { - errors = append(errors, fmt.Sprintf("error close stdin: %s", err)) + errs = append(errs, fmt.Sprintf("error close stdin: %s", err)) } } if err := c.stdout.Clean(); err != nil { - errors = append(errors, fmt.Sprintf("error close stdout: %s", err)) + errs = append(errs, fmt.Sprintf("error close stdout: %s", err)) } if err := c.stderr.Clean(); err != nil { - errors = append(errors, fmt.Sprintf("error close stderr: %s", err)) + errs = append(errs, fmt.Sprintf("error close stderr: %s", err)) } - if len(errors) > 0 { - return fmt.Errorf(strings.Join(errors, "\n")) + if len(errs) > 0 { + return errors.New(strings.Join(errs, "\n")) } return nil diff --git a/integration-cli/benchmark_test.go b/integration-cli/benchmark_test.go index ae93cf30de..a0070f5c4c 100644 --- a/integration-cli/benchmark_test.go +++ b/integration-cli/benchmark_test.go @@ -1,7 +1,7 @@ package main import ( - "fmt" + "errors" "os" "runtime" "strings" @@ -44,7 +44,7 @@ func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) args = append(args, sleepCommandForDaemonPlatform()...) out, _, err := dockerCmdWithError(args...) if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) return } @@ -57,29 +57,29 @@ func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) defer os.RemoveAll(tmpDir) out, _, err = dockerCmdWithError("cp", id+":/tmp", tmpDir) if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) return } out, _, err = dockerCmdWithError("kill", id) if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) } out, _, err = dockerCmdWithError("start", id) if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) } out, _, err = dockerCmdWithError("kill", id) if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) } // don't do an rm -f here since it can potentially ignore errors from the graphdriver out, _, err = dockerCmdWithError("rm", id) if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) } } }() @@ -89,7 +89,7 @@ func (s *DockerBenchmarkSuite) BenchmarkConcurrentContainerActions(c *testing.B) for i := 0; i < numIterations; i++ { out, _, err := dockerCmdWithError("ps") if err != nil { - chErr <- fmt.Errorf(out) + chErr <- errors.New(out) } } }() @@ -114,7 +114,7 @@ func (s *DockerBenchmarkSuite) BenchmarkLogsCLIRotateFollow(c *testing.B) { ch <- nil out, _, _ := dockerCmdWithError("logs", "-f", id) // if this returns at all, it's an error - ch <- fmt.Errorf(out) + ch <- errors.New(out) }() <-ch diff --git a/libnetwork/drivers/bridge/setup_ip_tables.go b/libnetwork/drivers/bridge/setup_ip_tables.go index 62e96d6e1c..2c4722c28a 100644 --- a/libnetwork/drivers/bridge/setup_ip_tables.go +++ b/libnetwork/drivers/bridge/setup_ip_tables.go @@ -364,7 +364,7 @@ func setINC(version iptables.IPVersion, iface string, enable bool) error { logrus.Warnf("Failed to rollback iptables rule after failure (%v): %v", err, err2) } } - return fmt.Errorf(msg) + return errors.New(msg) } logrus.Warn(msg) } diff --git a/libnetwork/sandbox_externalkey_unix.go b/libnetwork/sandbox_externalkey_unix.go index 2c0355ed33..bdf6dd0a76 100644 --- a/libnetwork/sandbox_externalkey_unix.go +++ b/libnetwork/sandbox_externalkey_unix.go @@ -5,6 +5,7 @@ package libnetwork import ( "encoding/json" + "errors" "flag" "fmt" "io" @@ -107,7 +108,7 @@ func processReturn(r io.Reader) error { return fmt.Errorf("failed to read buf in processReturn : %v", err) } if string(buf[0:n]) != success { - return fmt.Errorf(string(buf[0:n])) + return errors.New(string(buf[0:n])) } return nil }