Skip to content

Commit

Permalink
fix: improve error handling by using panic for flag retrieval failures
Browse files Browse the repository at this point in the history
  • Loading branch information
kmtym1998 committed Dec 12, 2024
1 parent 57c6894 commit e4c10ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
},
}

Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"embed"
"fmt"
"os"

"github.com/fatih/color"
"github.com/kmtym1998/gh-prowl/cmd"
Expand All @@ -15,6 +16,7 @@ func main() {
defer func() {
if r := recover(); r != nil {
color.Red(fmt.Sprint(r))
os.Exit(1)
}
}()

Expand Down

0 comments on commit e4c10ea

Please sign in to comment.