From 36d7acf33028970f3a6415b8279d176d1a6709cc Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Tue, 18 Dec 2018 12:26:21 +0000 Subject: [PATCH] etcdctl: fix interactive mode panic Don't panic if command is given in interactive mode, give a nice error message instead. Before: $ ./bin/etcdctl watch -i panic: runtime error: index out of range goroutine 1 [running]: etcdctl/ctlv3/command.watchInteractiveFunc(...) etcd/etcdctl/ctlv3/command/watch_command.go:104 ... After: $ ./bin/etcdctl watch -i Invalid command: (watch and progress supported) foo Invalid command foo (only support watch) --- etcdctl/ctlv3/command/watch_command.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etcdctl/ctlv3/command/watch_command.go b/etcdctl/ctlv3/command/watch_command.go index cadfa0a80..ce8425cbe 100644 --- a/etcdctl/ctlv3/command/watch_command.go +++ b/etcdctl/ctlv3/command/watch_command.go @@ -101,6 +101,10 @@ func watchInteractiveFunc(cmd *cobra.Command, osArgs []string, envKey, envRange l = strings.TrimSuffix(l, "\n") args := argify(l) + if len(args) < 1 { + fmt.Fprintf(os.Stderr, "Invalid command: %s (watch and progress supported)\n", l) + continue + } switch args[0] { case "watch": if len(args) < 2 && envKey == "" {