Skip to content

fix: preserve ExitError in error chain in run_workflow_validation.go#18282

Merged
pelikhan merged 2 commits intomainfrom
copilot/fix-error-chain-in-run-workflow-validation
Feb 25, 2026
Merged

fix: preserve ExitError in error chain in run_workflow_validation.go#18282
pelikhan merged 2 commits intomainfrom
copilot/fix-error-chain-in-run-workflow-validation

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

The ExitError branch in checkWorkflowExistsInRepo used %s to format stderr, silently dropping the original error from the chain — making errors.As(err, &exec.ExitError{}) always return false for callers on the path that matters most.

Change

  • pkg/cli/run_workflow_validation.go: switch ExitError branch from %s to %s: %w, preserving both the stderr diagnostic content and the wrapped original error.
// Before
return fmt.Errorf("failed to list workflows in repository '%s': %s",
    repoOverride, string(exitError.Stderr))  // ❌ breaks error chain

// After
return fmt.Errorf("failed to list workflows in repository '%s': %s: %w",
    repoOverride, string(exitError.Stderr), err)  // ✅ stderr + wrapped error

Now consistent with the sibling branch directly below it, which already used %w.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/owner/repo/actions/workflows
    • Triggering command: /usr/bin/gh gh workflow list --repo owner/repo --json name,path,state 0/x64/bin/git (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Fix broken error chain in run_workflow_validation.go ExitError branch</issue_title>
<issue_description>## Objective

Fix an inconsistent error wrapping in run_workflow_validation.go where the ExitError branch discards the original error, breaking errors.Is/errors.As chain inspection for callers.

Context

From Sergo analysis run §22372431560 (discussion #18227).

In pkg/cli/run_workflow_validation.go around line 286–290, the ExitError branch uses %s with only the stderr bytes, silently dropping the original error from the chain. The sibling branch immediately below correctly uses %w. This inconsistency means callers cannot use errors.As(err, &exec.ExitError{}) on the returned error for the case that matters most.

Current Code

// pkg/cli/run_workflow_validation.go:286-290
var exitError *exec.ExitError
if errors.As(err, &exitError) {
    return fmt.Errorf("failed to list workflows in repository '%s': %s",
        repoOverride, string(exitError.Stderr))  // ❌ %s drops original error
}
return fmt.Errorf("failed to list workflows in repository '%s': %w", repoOverride, err) // ✅ correct

Approach

Wrap the original err in the ExitError branch while still including the stderr output for diagnostics:

var exitError *exec.ExitError
if errors.As(err, &exitError) {
    return fmt.Errorf("failed to list workflows in repository '%s': %s: %w",
        repoOverride, string(exitError.Stderr), err)  // ✅ includes stderr AND wraps err
}
return fmt.Errorf("failed to list workflows in repository '%s': %w", repoOverride, err)

This preserves the original error chain so callers can still use errors.As(err, &exec.ExitError{}) on the returned error.

Files to Modify

  • pkg/cli/run_workflow_validation.go (~line 286–290)

Acceptance Criteria

  • The ExitError branch uses %w to wrap the original error
  • Stderr content is still included in the error message for diagnostics
  • errors.As(returnedErr, &exec.ExitError{}) returns true for the ExitError case
  • Existing tests pass

Generated by Plan Command for issue #discussion #18227

  • expires on Feb 27, 2026, 6:22 AM UTC

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix broken error chain in run_workflow_validation.go fix: preserve ExitError in error chain in run_workflow_validation.go Feb 25, 2026
@pelikhan pelikhan marked this pull request as ready for review February 25, 2026 06:34
Copilot AI review requested due to automatic review settings February 25, 2026 06:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a broken error chain in the validateRemoteWorkflow function where the ExitError branch was using %s format specifier instead of %w, preventing callers from using errors.As() to inspect the underlying error type.

Changes:

  • Updated error formatting in the ExitError branch to wrap the original error while preserving stderr diagnostic output

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit 602f411 into main Feb 25, 2026
110 checks passed
@pelikhan pelikhan deleted the copilot/fix-error-chain-in-run-workflow-validation branch February 25, 2026 06:39
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] Fix broken error chain in run_workflow_validation.go ExitError branch

3 participants