Skip to content

Commit

Permalink
gitops-pusher: friendlier error on invalid subcommand
Browse files Browse the repository at this point in the history
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 <git@tigermatt.uk>
  • Loading branch information
mhuxtable committed Apr 23, 2024
1 parent 9779eb6 commit 1e89fd4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/gitops-pusher/gitops-pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"context"
"crypto/sha256"
"encoding/json"
"errors"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 1e89fd4

Please sign in to comment.