Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 2, 2025

Batch 2 of Run→RunE migration. Converts core workflow operation commands to idiomatic Cobra error handling by using RunE instead of Run.

Changes

  • run (cmd/gh-aw/main.go): Return errors directly
  • status (pkg/cli/status.go): Return errors, remove unused imports
  • logs (pkg/cli/logs.go): Return errors via fmt.Errorf/errors.New
  • audit (pkg/cli/audit.go): Return errors directly

Pattern

// Before
Run: func(cmd *cobra.Command, args []string) {
    if err := doSomething(); err != nil {
        fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
        os.Exit(1)
    }
}

// After
RunE: func(cmd *cobra.Command, args []string) error {
    return doSomething()
}

Errors now propagate to Cobra and are handled by root command, eliminating scattered os.Exit(1) calls.

Related: #5300

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Migrate workflow commands (run, status, logs, audit) to RunE</issue_title>
<issue_description>## Objective

Migrate core workflow operation commands from Run to RunE for idiomatic error handling.

Context

This is Batch 2 of 5 in the Run→RunE migration. These are the most frequently used commands for workflow management.

Parent Issue: #5300
Depends on: Batch 1 (error formatter setup) must be completed first

Commands to Migrate

  1. run - Execute workflows
  2. status - Check workflow status
  3. logs - Download and view workflow logs
  4. audit - Investigate workflow failures

Approach

For each command file:

  1. Change Run: to RunE:
  2. Remove os.Exit(1) calls
  3. Return errors directly instead of handling them inline
  4. Keep console.FormatErrorMessage for now (handled by root command)

Pattern Example

Before:

Run: func(cmd *cobra.Command, args []string) {
    if err := cli.RunWorkflow(...); err != nil {
        fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
        os.Exit(1)
    }
}

After:

RunE: func(cmd *cobra.Command, args []string) error {
    return cli.RunWorkflow(...)
}

Files to Modify

  • pkg/cli/run_command.go
  • pkg/cli/status_command.go
  • pkg/cli/logs.go
  • pkg/cli/audit_command.go

Acceptance Criteria

  • All four command files use RunE instead of Run
  • No os.Exit(1) calls in any of these commands
  • Errors propagate correctly to Cobra
  • Error messages remain user-friendly
  • All existing tests pass
  • Manual testing confirms correct exit codes

Testing

# Build and test each command
make build

# Test run command
./gh-aw run --help
./gh-aw run nonexistent-workflow  # Should error gracefully

# Test status command
./gh-aw status --help
./gh-aw status

# Test logs command
./gh-aw logs --help
./gh-aw logs

# Test audit command
./gh-aw audit --help
./gh-aw audit 12345

# Run test suite
make test-unit

Related to #5300

AI generated by Plan Command for #5282

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 2, 2025 20:20
Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
- Change Run to RunE for idiomatic Cobra error handling
- Return errors directly instead of os.Exit(1)
- Remove unused imports in status.go
- Simplify error handling patterns in logs.go

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate workflow commands to RunE for error handling Migrate workflow commands (run, status, logs, audit) to RunE Dec 2, 2025
Copilot AI requested a review from mnkiefer December 2, 2025 20:39
@pelikhan pelikhan marked this pull request as ready for review December 2, 2025 21:08
@pelikhan pelikhan merged commit c1312a2 into main Dec 3, 2025
86 checks passed
@pelikhan pelikhan deleted the copilot/migrate-workflow-commands-to-rune branch December 3, 2025 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan] Migrate workflow commands (run, status, logs, audit) to RunE

3 participants