-
Notifications
You must be signed in to change notification settings - Fork 47
Closed
1 / 11 of 1 issue completedClosed
1 / 11 of 1 issue completed
Copy link
Labels
Description
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:toRunE: - Remove
os.Exit(1)calls - Return errors directly
- Keep console formatting for now (can standardize later)
- Change
-
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 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.go- All other command files in
pkg/cli/
Acceptance Criteria
- All commands use
RunEinstead ofRun - No
os.Exit(1)calls in command functions - Errors are returned directly to Cobra
- Error formatting still uses
console.FormatErrorMessage - All existing tests pass
- Error messages remain user-friendly
- Exit codes are correct (non-zero on errors)
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
Reactions are currently unavailable