Skip to content

Commit

Permalink
etcdctl: fix interactive mode panic
Browse files Browse the repository at this point in the history
Don't panic if command is given in interactive mode, give a nice error
message instead.

Before:

 $ ./bin/etcdctl watch -i
 <hit return>
 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
 <hit return>
 Invalid command:  (watch and progress supported)
 foo
 Invalid command foo (only support watch)
  • Loading branch information
markmc committed Jan 14, 2019
1 parent 1eee465 commit 36d7acf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions etcdctl/ctlv3/command/watch_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down

0 comments on commit 36d7acf

Please sign in to comment.