From 3306b98615520d3ca49bd5d10959d819d2f2fca7 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Thu, 17 Oct 2024 21:48:18 +0000 Subject: [PATCH] Add error handling Signed-off-by: Harald Albers --- cli/command/system/completion.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/command/system/completion.go b/cli/command/system/completion.go index 21e0623f986f..4e52f88e5e3f 100644 --- a/cli/command/system/completion.go +++ b/cli/command/system/completion.go @@ -52,14 +52,16 @@ var ( "untag", "update", } + eventTypes = []string{"config", "container", "daemon", "image", "network", "node", "plugin", "secret", "service", "volume"} ) -var eventTypes = []string{"config", "container", "daemon", "image", "network", "node", "plugin", "secret", "service", "volume"} func completeFilters(dockerCLI completion.APIClientProvider) completion.ValidArgsFn { return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if strings.HasPrefix(toComplete, "container=") { - // the pure container name list should be pulled out from ContainerNames. names, _ := completion.ContainerNames(dockerCLI, true)(cmd, args, toComplete) + if names == nil { + return nil, cobra.ShellCompDirectiveNoFileComp + } return prefixWith("container=", names), cobra.ShellCompDirectiveDefault } if strings.HasPrefix(toComplete, "event=") { @@ -69,8 +71,10 @@ func completeFilters(dockerCLI completion.APIClientProvider) completion.ValidArg return nil, cobra.ShellCompDirectiveNoFileComp } if strings.HasPrefix(toComplete, "network=") { - // the pure network name list should be pulled out from NetworkNames. names, _ := completion.NetworkNames(dockerCLI)(cmd, args, toComplete) + if names == nil { + return nil, cobra.ShellCompDirectiveNoFileComp + } return prefixWith("network=", names), cobra.ShellCompDirectiveDefault } if strings.HasPrefix(toComplete, "type=") {