Merge pull request #3044 from cpuguy83/fix_info_output

info: print errors to stderr
This commit is contained in:
Sebastiaan van Stijn 2021-07-13 17:58:33 +02:00 committed by GitHub
commit 9262fad23b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 14 deletions

View File

@ -136,7 +136,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error {
prettyPrintClientInfo(dockerCli, *info.ClientInfo) prettyPrintClientInfo(dockerCli, *info.ClientInfo)
} }
for _, err := range info.ClientErrors { for _, err := range info.ClientErrors {
fmt.Fprintln(dockerCli.Out(), "ERROR:", err) fmt.Fprintln(dockerCli.Err(), "ERROR:", err)
} }
fmt.Fprintln(dockerCli.Out()) fmt.Fprintln(dockerCli.Out())
@ -147,7 +147,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error {
} }
} }
for _, err := range info.ServerErrors { 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 { if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 {

View File

@ -340,20 +340,22 @@ func TestPrettyPrintInfo(t *testing.T) {
ServerErrors: []string{"a server error occurred"}, ServerErrors: []string{"a server error occurred"},
ClientErrors: []string{"a client error occurred"}, ClientErrors: []string{"a client error occurred"},
}, },
prettyGolden: "docker-info-errors", prettyGolden: "docker-info-errors",
jsonGolden: "docker-info-errors", jsonGolden: "docker-info-errors",
expectedError: "errors pretty printing info", warningsGolden: "docker-info-errors-stderr",
expectedError: "errors pretty printing info",
}, },
{ {
doc: "bad security info", doc: "bad security info",
dockerInfo: info{ dockerInfo: info{
Info: &sampleInfoBadSecurity, Info: &sampleInfoBadSecurity,
ServerErrors: []string{"an error happened"}, ServerErrors: []string{"a server error occurred"},
ClientInfo: &clientInfo{Debug: false}, ClientInfo: &clientInfo{Debug: false},
}, },
prettyGolden: "docker-info-badsec", prettyGolden: "docker-info-badsec",
jsonGolden: "docker-info-badsec", jsonGolden: "docker-info-badsec",
expectedError: "errors pretty printing info", warningsGolden: "docker-info-badsec-stderr",
expectedError: "errors pretty printing info",
}, },
} { } {
t.Run(tc.doc, func(t *testing.T) { t.Run(tc.doc, func(t *testing.T) {

View File

@ -0,0 +1,2 @@
ERROR: a server error occurred
ERROR: invalid empty security option

View File

@ -51,5 +51,3 @@ Server:
Default Address Pools: Default Address Pools:
Base: 10.123.0.0/16, Size: 24 Base: 10.123.0.0/16, Size: 24
ERROR: an error happened
ERROR: invalid empty security option

View File

@ -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}}

View File

@ -0,0 +1,2 @@
ERROR: a client error occurred
ERROR: a server error occurred

View File

@ -1,5 +1,3 @@
Client: Client:
ERROR: a client error occurred
Server: Server:
ERROR: a server error occurred