From 210ab030bc3dab7bcf8f7252f2f9facb5a26cb6b Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Mon, 16 Mar 2015 09:35:15 +0100 Subject: [PATCH] Format error by value - Use `%v` verb to format errors. - Give `param` constant in portallocator some better name. Signed-off-by: Michal Minar --- api/client/commands.go | 4 ++-- api/common.go | 2 +- api/server/server.go | 4 ++-- builder/internals.go | 2 +- builder/parser/parser_test.go | 8 ++++---- daemon/daemon.go | 4 ++-- daemon/graphdriver/graphtest/graphtest.go | 2 +- daemon/networkdriver/bridge/driver.go | 2 +- daemon/networkdriver/portallocator/portallocator.go | 8 ++++---- daemon/start.go | 2 +- daemon/wait.go | 2 +- integration/runtime_test.go | 2 +- .../github.com/coreos/go-systemd/activation/listeners.go | 2 +- .../src/github.com/docker/libcontainer/user/user_test.go | 4 ++-- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/api/client/commands.go b/api/client/commands.go index e10bee3b18..298120260a 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -912,7 +912,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error { obj, _, err := readBody(cli.call("GET", "/containers/"+name+"/json", nil, false)) if err != nil { if strings.Contains(err.Error(), "Too many") { - fmt.Fprintf(cli.err, "Error: %s", err.Error()) + fmt.Fprintf(cli.err, "Error: %v", err) status = 1 continue } @@ -2787,7 +2787,7 @@ func (cli *DockerCli) CmdStats(args ...string) error { for _, c := range cStats { c.mu.Lock() if c.err != nil { - errs = append(errs, fmt.Sprintf("%s: %s", c.Name, c.err.Error())) + errs = append(errs, fmt.Sprintf("%s: %v", c.Name, c.err)) } c.mu.Unlock() } diff --git a/api/common.go b/api/common.go index 9e85c5ec3b..f6a0bc4883 100644 --- a/api/common.go +++ b/api/common.go @@ -104,7 +104,7 @@ func FormGroup(key string, start, last int) string { func MatchesContentType(contentType, expectedType string) bool { mimetype, _, err := mime.ParseMediaType(contentType) if err != nil { - log.Errorf("Error parsing media type: %s error: %s", contentType, err.Error()) + log.Errorf("Error parsing media type: %s error: %v", contentType, err) } return err == nil && mimetype == expectedType } diff --git a/api/server/server.go b/api/server/server.go index 82395187eb..50869c3609 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -135,7 +135,7 @@ func httpError(w http.ResponseWriter, err error) { } if err != nil { - log.Errorf("HTTP Error: statusCode=%d %s", statusCode, err.Error()) + log.Errorf("HTTP Error: statusCode=%d %v", statusCode, err) http.Error(w, err.Error(), statusCode) } } @@ -1123,7 +1123,7 @@ func postContainersCopy(eng *engine.Engine, version version.Version, w http.Resp job.Stdout.Add(w) w.Header().Set("Content-Type", "application/x-tar") if err := job.Run(); err != nil { - log.Errorf("%s", err.Error()) + log.Errorf("%v", err) if strings.Contains(strings.ToLower(err.Error()), "no such id") { w.WriteHeader(http.StatusNotFound) } else if strings.Contains(err.Error(), "no such file or directory") { diff --git a/builder/internals.go b/builder/internals.go index f6b929f2b6..0214b5a89b 100644 --- a/builder/internals.go +++ b/builder/internals.go @@ -725,7 +725,7 @@ func (b *Builder) clearTmp() { } if err := b.Daemon.Rm(tmp); err != nil { - fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %s\n", common.TruncateID(c), err.Error()) + fmt.Fprintf(b.OutStream, "Error removing intermediate container %s: %v\n", common.TruncateID(c), err) return } b.Daemon.DeleteVolumes(tmp.VolumePaths()) diff --git a/builder/parser/parser_test.go b/builder/parser/parser_test.go index dcd684d645..6b55a611ec 100644 --- a/builder/parser/parser_test.go +++ b/builder/parser/parser_test.go @@ -33,7 +33,7 @@ func TestTestNegative(t *testing.T) { df, err := os.Open(dockerfile) if err != nil { - t.Fatalf("Dockerfile missing for %s: %s", dir, err.Error()) + t.Fatalf("Dockerfile missing for %s: %v", dir, err) } _, err = Parse(df) @@ -52,18 +52,18 @@ func TestTestData(t *testing.T) { df, err := os.Open(dockerfile) if err != nil { - t.Fatalf("Dockerfile missing for %s: %s", dir, err.Error()) + t.Fatalf("Dockerfile missing for %s: %v", dir, err) } defer df.Close() ast, err := Parse(df) if err != nil { - t.Fatalf("Error parsing %s's dockerfile: %s", dir, err.Error()) + t.Fatalf("Error parsing %s's dockerfile: %v", dir, err) } content, err := ioutil.ReadFile(resultfile) if err != nil { - t.Fatalf("Error reading %s's result file: %s", dir, err.Error()) + t.Fatalf("Error reading %s's result file: %v", dir, err) } if ast.Dump()+"\n" != string(content) { diff --git a/daemon/daemon.go b/daemon/daemon.go index f249a816a9..aec26eb5d7 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1015,10 +1015,10 @@ func NewDaemonFromDirectory(config *Config, eng *engine.Engine) (*Daemon, error) log.Errorf("portallocator.ReleaseAll(): %s", err) } if err := daemon.driver.Cleanup(); err != nil { - log.Errorf("daemon.driver.Cleanup(): %s", err.Error()) + log.Errorf("daemon.driver.Cleanup(): %v", err) } if err := daemon.containerGraph.Close(); err != nil { - log.Errorf("daemon.containerGraph.Close(): %s", err.Error()) + log.Errorf("daemon.containerGraph.Close(): %v", err) } }) diff --git a/daemon/graphdriver/graphtest/graphtest.go b/daemon/graphdriver/graphtest/graphtest.go index 4f14e7aed4..2bd30f6aeb 100644 --- a/daemon/graphdriver/graphtest/graphtest.go +++ b/daemon/graphdriver/graphtest/graphtest.go @@ -73,7 +73,7 @@ func newDriver(t *testing.T, name string) *Driver { d, err := graphdriver.GetDriver(name, root, nil) if err != nil { - t.Logf("graphdriver: %s\n", err.Error()) + t.Logf("graphdriver: %v\n", err) if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites || err == graphdriver.ErrIncompatibleFS { t.Skipf("Driver %s not supported", name) } diff --git a/daemon/networkdriver/bridge/driver.go b/daemon/networkdriver/bridge/driver.go index 329052be41..96b0d6834c 100644 --- a/daemon/networkdriver/bridge/driver.go +++ b/daemon/networkdriver/bridge/driver.go @@ -530,7 +530,7 @@ func Allocate(job *engine.Job) engine.Status { globalIPv6, err = ipallocator.RequestIP(globalIPv6Network, requestedIPv6) if err != nil { - log.Errorf("Allocator: RequestIP v6: %s", err.Error()) + log.Errorf("Allocator: RequestIP v6: %v", err) return job.Error(err) } log.Infof("Allocated IPv6 %s", globalIPv6) diff --git a/daemon/networkdriver/portallocator/portallocator.go b/daemon/networkdriver/portallocator/portallocator.go index 4ae4beb106..97f847ecb2 100644 --- a/daemon/networkdriver/portallocator/portallocator.go +++ b/daemon/networkdriver/portallocator/portallocator.go @@ -69,11 +69,11 @@ func NewErrPortAlreadyAllocated(ip string, port int) ErrPortAlreadyAllocated { } func init() { - const param = "/proc/sys/net/ipv4/ip_local_port_range" + const portRangeKernelParam = "/proc/sys/net/ipv4/ip_local_port_range" - file, err := os.Open(param) + file, err := os.Open(portRangeKernelParam) if err != nil { - log.Errorf("Failed to read %s kernel parameter: %s", param, err.Error()) + log.Errorf("Failed to read %s kernel parameter: %v", portRangeKernelParam, err) return } var start, end int @@ -82,7 +82,7 @@ func init() { if err == nil { err = fmt.Errorf("unexpected count of parsed numbers (%d)", n) } - log.Errorf("Failed to parse port range from %s: %v", param, err) + log.Errorf("Failed to parse port range from %s: %v", portRangeKernelParam, err) return } beginPortRange = start diff --git a/daemon/start.go b/daemon/start.go index e5076d9128..e51ada22a2 100644 --- a/daemon/start.go +++ b/daemon/start.go @@ -66,7 +66,7 @@ func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig. if err != nil && os.IsNotExist(err) { err = os.MkdirAll(source, 0755) if err != nil { - return fmt.Errorf("Could not create local directory '%s' for bind mount: %s!", source, err.Error()) + return fmt.Errorf("Could not create local directory '%s' for bind mount: %v!", source, err) } } } diff --git a/daemon/wait.go b/daemon/wait.go index e2747a3e42..7579467a00 100644 --- a/daemon/wait.go +++ b/daemon/wait.go @@ -13,7 +13,7 @@ func (daemon *Daemon) ContainerWait(job *engine.Job) engine.Status { name := job.Args[0] container, err := daemon.Get(name) if err != nil { - return job.Errorf("%s: %s", job.Name, err.Error()) + return job.Errorf("%s: %v", job.Name, err) } status, _ := container.WaitStop(-1 * time.Second) job.Printf("%d\n", status) diff --git a/integration/runtime_test.go b/integration/runtime_test.go index f421facde3..153c385627 100644 --- a/integration/runtime_test.go +++ b/integration/runtime_test.go @@ -307,7 +307,7 @@ func TestDaemonCreate(t *testing.T) { "conflictname", ) if _, _, err := daemon.Create(&runconfig.Config{Image: GetTestImage(daemon).ID, Cmd: []string{"ls", "-al"}}, &runconfig.HostConfig{}, testContainer.Name); err == nil || !strings.Contains(err.Error(), common.TruncateID(testContainer.ID)) { - t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %s", err.Error()) + t.Fatalf("Name conflict error doesn't include the correct short id. Message was: %v", err) } // Make sure create with bad parameters returns an error diff --git a/vendor/src/github.com/coreos/go-systemd/activation/listeners.go b/vendor/src/github.com/coreos/go-systemd/activation/listeners.go index cdb2cf4bb4..48584a9b5e 100644 --- a/vendor/src/github.com/coreos/go-systemd/activation/listeners.go +++ b/vendor/src/github.com/coreos/go-systemd/activation/listeners.go @@ -30,7 +30,7 @@ func Listeners(unsetEnv bool) ([]net.Listener, error) { var err error listeners[i], err = net.FileListener(f) if err != nil { - return nil, fmt.Errorf("Error setting up FileListener for fd %d: %s", f.Fd(), err.Error()) + return nil, fmt.Errorf("Error setting up FileListener for fd %d: %v", f.Fd(), err) } } diff --git a/vendor/src/github.com/docker/libcontainer/user/user_test.go b/vendor/src/github.com/docker/libcontainer/user/user_test.go index 4fe008fb39..1a7318e065 100644 --- a/vendor/src/github.com/docker/libcontainer/user/user_test.go +++ b/vendor/src/github.com/docker/libcontainer/user/user_test.go @@ -198,7 +198,7 @@ this is just some garbage data execUser, err := GetExecUser(test.ref, &defaultExecUser, passwd, group) if err != nil { - t.Logf("got unexpected error when parsing '%s': %s", test.ref, err.Error()) + t.Logf("got unexpected error when parsing '%s': %v", test.ref, err) t.Fail() continue } @@ -337,7 +337,7 @@ this is just some garbage data execUser, err := GetExecUser(test.ref, &defaultExecUser, passwd, group) if err != nil { - t.Logf("got unexpected error when parsing '%s': %s", test.ref, err.Error()) + t.Logf("got unexpected error when parsing '%s': %v", test.ref, err) t.Fail() continue }