diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d9ec7943..c7098cc4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -168,6 +168,13 @@ jobs: fi working-directory: ./cmd/river + - name: river unknown command (expect failure) + run: | + if ./river not-a-command; then + echo "expected non-zero exit code" && exit 1 + fi + working-directory: ./cmd/river + golangci: name: lint runs-on: ubuntu-latest diff --git a/cmd/river/main.go b/cmd/river/main.go index 4f0e1032..8877a375 100644 --- a/cmd/river/main.go +++ b/cmd/river/main.go @@ -234,10 +234,12 @@ migrations that need to be run, but without running them. rootCmd.AddCommand(cmd) } - // Cobra will already print an error on an uknown command, and there aren't - // really any other important top-level error cases to worry about as far as - // I can tell, so ignore a returned error here so we don't double print it. - _ = rootCmd.Execute() + if err := rootCmd.Execute(); err != nil { + // Cobra will already print an error on problems like an unknown command + // or missing required flag. Set an exit status of 1 on error, but don't + // print it again. + os.Exit(1) + } } func openDBPool(ctx context.Context, databaseURL string) (*pgxpool.Pool, error) {