From 1e89fd4185dcf984d6379359be28cb2bed0b463d Mon Sep 17 00:00:00 2001 From: Matthew Huxtable Date: Tue, 23 Apr 2024 11:53:39 +0100 Subject: [PATCH] gitops-pusher: friendlier error on invalid subcommand If an invalid subcommand was provided to the gitops-pusher (e.g. I mistakenly passed 'sync' rather than the expected 'apply'), the error rendered from ffcli does not make this obvious to the operator, particularly when rendered in a CI pipeline. The error was: terminal command () doesn't define an Exec function This trivial change catches the ffcli error and provides a friendlier error to the user to hopefully aid their diagnosis of the problem in these cases. Fixes #11842. Signed-off-by: Matthew Huxtable --- cmd/gitops-pusher/gitops-pusher.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/gitops-pusher/gitops-pusher.go b/cmd/gitops-pusher/gitops-pusher.go index 60bee6064d439..55558a1f83f63 100644 --- a/cmd/gitops-pusher/gitops-pusher.go +++ b/cmd/gitops-pusher/gitops-pusher.go @@ -11,6 +11,7 @@ import ( "context" "crypto/sha256" "encoding/json" + "errors" "flag" "fmt" "log" @@ -216,6 +217,14 @@ func main() { } if err := root.Parse(os.Args[1:]); err != nil { + if noexec := (ffcli.NoExecError{}); errors.As(err, &noexec) { + if args := noexec.Command.FlagSet.Args(); len(args) > 0 { + log.Fatalf("invalid subcommand %s, see -help for available subcommands", args[0]) + } else { + log.Fatal("missing subcommand, see -help for available subcommands") + } + } + log.Fatal(err) }