Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

info: improve handling of empty Info #3594

Merged
merged 2 commits into from
May 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
}

func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error {
var info info

info.ClientInfo = &clientInfo{
Context: dockerCli.CurrentContext(),
Debug: debug.IsEnabled(),
info := info{
ClientInfo: &clientInfo{
Context: dockerCli.CurrentContext(),
Debug: debug.IsEnabled(),
},
Info: &types.Info{},
}
if plugins, err := pluginmanager.ListPlugins(dockerCli, cmd.Root()); err == nil {
info.ClientInfo.Plugins = plugins
Expand All @@ -85,6 +86,16 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error
info.Info = &dinfo
} else {
info.ServerErrors = append(info.ServerErrors, err.Error())
if opts.format == "" {
// reset the server info to prevent printing "empty" Server info
// and warnings, but don't reset it if a custom format was specified
// to prevent errors from Go's template parsing during format.
info.Info = nil
} else {
// if a format is provided, print the error, as it may be hidden
// otherwise if the template doesn't include the ServerErrors field.
fmt.Fprintln(dockerCli.Err(), err)
}
}
}

Expand Down