From c6b3fcbe3290c79689a2c941273982d79b8fc5a1 Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Fri, 16 Dec 2016 12:17:39 -0800 Subject: [PATCH] Improve error output for `docker stats ...` While looking into `docker stats ...` I noticed that the error output is quite long, especially if there are multiple errors: ```sh ubuntu@ubuntu:~/docker$ docker stats nofound : Error response from daemon: No such container: nofound ubuntu@ubuntu:~/docker$ docker stats nofound foo bar : Error response from daemon: No such container: nofound, : Error response from daemon: No such container: foo, : Error response from daemon: No such container: bar ``` There are several issues, 1. There is an extra `: ` at the beginning. That is because if container is not found, the name will not be available from the daemon. 2. Multiple errors are concatenated with `, ` which will be quite long. This fix: 1. Only prient out the error from daemon. 2. Multiple errors are printed out line by line. Below is the new output: ```sh ubuntu@ubuntu:~/docker$ docker stats nofound Error response from daemon: No such container: nofound ubuntu@ubuntu:~/docker$ docker stats nofound foo bar Error response from daemon: No such container: nofound Error response from daemon: No such container: foo Error response from daemon: No such container: bar ``` Signed-off-by: Yong Tang --- command/container/stats.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/command/container/stats.go b/command/container/stats.go index 12d5c68522..ebbd36e7e4 100644 --- a/command/container/stats.go +++ b/command/container/stats.go @@ -173,14 +173,13 @@ func runStats(dockerCli *command.DockerCli, opts *statsOptions) error { var errs []string cStats.mu.Lock() for _, c := range cStats.cs { - cErr := c.GetError() - if cErr != nil { - errs = append(errs, fmt.Sprintf("%s: %v", c.Name, cErr)) + if err := c.GetError(); err != nil { + errs = append(errs, err.Error()) } } cStats.mu.Unlock() if len(errs) > 0 { - return fmt.Errorf("%s", strings.Join(errs, ", ")) + return fmt.Errorf("%s", strings.Join(errs, "\n")) } }