Objective
Migrate all command implementations from using Run to RunE for more idiomatic error handling across the entire CLI codebase.
Context
Current State: 107 commands use Run with manual error handling, only 4 use RunE
This migration will eliminate repetitive error handling code and adopt Go best practices for error propagation in CLI applications.
Current Pattern (Anti-pattern)
Run: func(cmd *cobra.Command, args []string) {
if err := cli.NewWorkflow(...); err != nil {
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
os.Exit(1)
}
}
Target Pattern (Idiomatic)
RunE: func(cmd *cobra.Command, args []string) error {
return cli.NewWorkflow(...)
}
Approach
-
Create error formatter wrapper in cmd/gh-aw/main.go:
rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
return err
})
-
Migrate commands in batches to make review manageable:
- Batch 1: Root command and compile commands
- Batch 2: Workflow commands (run, status, logs, audit)
- Batch 3: MCP commands
- Batch 4: Development utilities
- Batch 5: Remaining commands
-
Update each command:
- Change
Run: to RunE:
- Remove
os.Exit(1) calls
- Return errors directly
- Keep console formatting for now (can standardize later)
-
Test each batch to ensure error handling still works correctly
Files to Modify
Core files (16+ files):
cmd/gh-aw/main.go - Root command and inline commands
pkg/cli/compile_command.go
pkg/cli/run_command.go
pkg/cli/status_command.go
pkg/cli/logs.go
pkg/cli/audit_command.go
pkg/cli/mcp_command.go
pkg/cli/mcp_inspect_command.go
pkg/cli/mcp_list_tools_command.go
pkg/cli/pr_command.go
pkg/cli/trial_command.go
pkg/cli/workflow_dispatch_command.go
- All other command files in
pkg/cli/
Acceptance Criteria
Benefits
- ✅ More idiomatic Go error handling
- ✅ Eliminates 107 instances of repetitive error handling
- ✅ Cleaner, more maintainable code
- ✅ Consistent error propagation pattern
- ✅ Easier to add error context in future
Notes
- This is the highest impact improvement identified in the Go Fan analysis
- Changes affect the entire CLI codebase
- Breaking this into batches will make code review manageable
- Can be done without changing external behavior
AI generated by Plan Command for discussion #5271
Objective
Migrate all command implementations from using
RuntoRunEfor more idiomatic error handling across the entire CLI codebase.Context
Current State: 107 commands use
Runwith manual error handling, only 4 useRunEThis migration will eliminate repetitive error handling code and adopt Go best practices for error propagation in CLI applications.
Current Pattern (Anti-pattern)
Target Pattern (Idiomatic)
Approach
Create error formatter wrapper in
cmd/gh-aw/main.go:Migrate commands in batches to make review manageable:
Update each command:
Run:toRunE:os.Exit(1)callsTest each batch to ensure error handling still works correctly
Files to Modify
Core files (16+ files):
cmd/gh-aw/main.go- Root command and inline commandspkg/cli/compile_command.gopkg/cli/run_command.gopkg/cli/status_command.gopkg/cli/logs.gopkg/cli/audit_command.gopkg/cli/mcp_command.gopkg/cli/mcp_inspect_command.gopkg/cli/mcp_list_tools_command.gopkg/cli/pr_command.gopkg/cli/trial_command.gopkg/cli/workflow_dispatch_command.gopkg/cli/Acceptance Criteria
RunEinstead ofRunos.Exit(1)calls in command functionsconsole.FormatErrorMessageBenefits
Notes