From 4ce521c5031ac0d912b34c33d67f8d810edc40d7 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Thu, 8 Apr 2021 23:46:13 +0000 Subject: [PATCH] info: print errors to stderr Errors always need to go to stderr. This also fixes a test in moby/moby's integration-cli which is checking to see if errors connecting to the daemon are output on stderr. Signed-off-by: Brian Goff Signed-off-by: Sebastiaan van Stijn --- cli/command/system/info.go | 4 ++-- cli/command/system/info_test.go | 16 +++++++++------- .../testdata/docker-info-badsec-stderr.golden | 2 ++ .../system/testdata/docker-info-badsec.golden | 2 -- .../testdata/docker-info-badsec.json.golden | 2 +- .../testdata/docker-info-errors-stderr.golden | 2 ++ .../system/testdata/docker-info-errors.golden | 2 -- 7 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 cli/command/system/testdata/docker-info-badsec-stderr.golden create mode 100644 cli/command/system/testdata/docker-info-errors-stderr.golden diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 452ba21644..dfa90702c3 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -136,7 +136,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error { prettyPrintClientInfo(dockerCli, *info.ClientInfo) } for _, err := range info.ClientErrors { - fmt.Fprintln(dockerCli.Out(), "ERROR:", err) + fmt.Fprintln(dockerCli.Err(), "ERROR:", err) } fmt.Fprintln(dockerCli.Out()) @@ -147,7 +147,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error { } } for _, err := range info.ServerErrors { - fmt.Fprintln(dockerCli.Out(), "ERROR:", err) + fmt.Fprintln(dockerCli.Err(), "ERROR:", err) } if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 { diff --git a/cli/command/system/info_test.go b/cli/command/system/info_test.go index 18453e9c26..bbd0288057 100644 --- a/cli/command/system/info_test.go +++ b/cli/command/system/info_test.go @@ -340,20 +340,22 @@ func TestPrettyPrintInfo(t *testing.T) { ServerErrors: []string{"a server error occurred"}, ClientErrors: []string{"a client error occurred"}, }, - prettyGolden: "docker-info-errors", - jsonGolden: "docker-info-errors", - expectedError: "errors pretty printing info", + prettyGolden: "docker-info-errors", + jsonGolden: "docker-info-errors", + warningsGolden: "docker-info-errors-stderr", + expectedError: "errors pretty printing info", }, { doc: "bad security info", dockerInfo: info{ Info: &sampleInfoBadSecurity, - ServerErrors: []string{"an error happened"}, + ServerErrors: []string{"a server error occurred"}, ClientInfo: &clientInfo{Debug: false}, }, - prettyGolden: "docker-info-badsec", - jsonGolden: "docker-info-badsec", - expectedError: "errors pretty printing info", + prettyGolden: "docker-info-badsec", + jsonGolden: "docker-info-badsec", + warningsGolden: "docker-info-badsec-stderr", + expectedError: "errors pretty printing info", }, } { t.Run(tc.doc, func(t *testing.T) { diff --git a/cli/command/system/testdata/docker-info-badsec-stderr.golden b/cli/command/system/testdata/docker-info-badsec-stderr.golden new file mode 100644 index 0000000000..72a09117c3 --- /dev/null +++ b/cli/command/system/testdata/docker-info-badsec-stderr.golden @@ -0,0 +1,2 @@ +ERROR: a server error occurred +ERROR: invalid empty security option diff --git a/cli/command/system/testdata/docker-info-badsec.golden b/cli/command/system/testdata/docker-info-badsec.golden index 2a12174af2..e25ac7c0cf 100644 --- a/cli/command/system/testdata/docker-info-badsec.golden +++ b/cli/command/system/testdata/docker-info-badsec.golden @@ -51,5 +51,3 @@ Server: Default Address Pools: Base: 10.123.0.0/16, Size: 24 -ERROR: an error happened -ERROR: invalid empty security option diff --git a/cli/command/system/testdata/docker-info-badsec.json.golden b/cli/command/system/testdata/docker-info-badsec.json.golden index 6180cb91df..3fc32aeef3 100644 --- a/cli/command/system/testdata/docker-info-badsec.json.golden +++ b/cli/command/system/testdata/docker-info-badsec.json.golden @@ -1 +1 @@ -{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":false,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":false,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":33,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["foo="],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":null,"ServerErrors":["an error happened"],"ClientInfo":{"Debug":false,"Context":"","Plugins":[],"Warnings":null}} +{"ID":"EKHL:QDUU:QZ7U:MKGD:VDXK:S27Q:GIPU:24B7:R7VT:DGN6:QCSF:2UBX","Containers":0,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":0,"Images":0,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","0"],["Dirperm1 Supported","true"]],"Plugins":{"Volume":["local"],"Network":["bridge","host","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"KernelMemoryTCP":false,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":false,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":true,"NFd":33,"OomKillDisable":true,"NGoroutines":135,"SystemTime":"2017-08-24T17:44:34.077811894Z","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"4.4.0-87-generic","OperatingSystem":"Ubuntu 16.04.3 LTS","OSVersion":"","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":null,"Secure":true,"Official":true}},"Mirrors":null},"NCPU":2,"MemTotal":2097356800,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"system-sample","Labels":["provider=digitalocean"],"ExperimentalBuild":false,"ServerVersion":"17.06.1-ce","Runtimes":{"runc":{"path":"docker-runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"6e23458c129b551d5c9871e5174f6b1b7f6d1170","Expected":"6e23458c129b551d5c9871e5174f6b1b7f6d1170"},"RuncCommit":{"ID":"810190ceaa507aa2727d7ae6f4790c76ec150bd2","Expected":"810190ceaa507aa2727d7ae6f4790c76ec150bd2"},"InitCommit":{"ID":"949e6fa","Expected":"949e6fa"},"SecurityOptions":["foo="],"DefaultAddressPools":[{"Base":"10.123.0.0/16","Size":24}],"Warnings":null,"ServerErrors":["a server error occurred"],"ClientInfo":{"Debug":false,"Context":"","Plugins":[],"Warnings":null}} diff --git a/cli/command/system/testdata/docker-info-errors-stderr.golden b/cli/command/system/testdata/docker-info-errors-stderr.golden new file mode 100644 index 0000000000..ecf9701b86 --- /dev/null +++ b/cli/command/system/testdata/docker-info-errors-stderr.golden @@ -0,0 +1,2 @@ +ERROR: a client error occurred +ERROR: a server error occurred diff --git a/cli/command/system/testdata/docker-info-errors.golden b/cli/command/system/testdata/docker-info-errors.golden index 549611ee13..623b21238b 100644 --- a/cli/command/system/testdata/docker-info-errors.golden +++ b/cli/command/system/testdata/docker-info-errors.golden @@ -1,5 +1,3 @@ Client: -ERROR: a client error occurred Server: -ERROR: a server error occurred