From e4c10ea0aa4b3ce6084fe6c0b7e9ba0f367a0fff Mon Sep 17 00:00:00 2001 From: kmtym1998 Date: Fri, 13 Dec 2024 01:37:08 +0900 Subject: [PATCH] fix: improve error handling by using panic for flag retrieval failures --- cmd/root.go | 14 ++++++++------ main.go | 2 ++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 22e8a3c..34f4bb6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,31 +28,33 @@ func NewRootCmd(ec *ExecutionContext) *cobra.Command { Use: "gh-prowl", Short: "Track the progress of repository checks and notify upon completion", Long: `This command allows you to monitor the status of GitHub Actions checks for a pull request (PR) or a specific branch. If used with the "--current-branch" flag, it monitors the PR associated with the current branch. Otherwise, you can select a PR or specify a branch manually.`, - RunE: func(cmd *cobra.Command, args []string) error { + Run: func(cmd *cobra.Command, args []string) { current, err := cmd.Flags().GetBool("current-branch") if err != nil { - return fmt.Errorf("failed to get flag: %w", err) + panic(fmt.Errorf("failed to get flag: %w", err)) } targetRef, err := cmd.Flags().GetString("ref") if err != nil { - return fmt.Errorf("failed to get flag: %w", err) + panic(fmt.Errorf("failed to get flag: %w", err)) } silent, err := cmd.Flags().GetBool("silent") if err != nil { - return fmt.Errorf("failed to get flag: %w", err) + panic(fmt.Errorf("failed to get flag: %w", err)) } if silent { ec.SoundNotifier = notify.NewNoopNotifier() } - return rootRunE(&rootOption{ + if err := rootRunE(&rootOption{ ec: ec, current: current, targetRef: targetRef, - }) + }); err != nil { + panic(err.Error()) + } }, } diff --git a/main.go b/main.go index 90457cb..6a5b09e 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "embed" "fmt" + "os" "github.com/fatih/color" "github.com/kmtym1998/gh-prowl/cmd" @@ -15,6 +16,7 @@ func main() { defer func() { if r := recover(); r != nil { color.Red(fmt.Sprint(r)) + os.Exit(1) } }()