Skip to content

fix(copilot): hint to run copilot directly when exec fails#13393

Open
babakks wants to merge 1 commit into
trunkfrom
babakks/improve-gh-copilot-error
Open

fix(copilot): hint to run copilot directly when exec fails#13393
babakks wants to merge 1 commit into
trunkfrom
babakks/improve-gh-copilot-error

Conversation

@babakks
Copy link
Copy Markdown
Member

@babakks babakks commented May 11, 2026

Summary

When gh copilot finds the copilot binary in PATH but fails to execute it (e.g., due to unusual characters like parentheses in the file path on Windows), the error message now includes a hint:

Try running `copilot` directly without `gh`

The hint is only shown when the binary was already present on the host, not when it was freshly downloaded and installed by gh.

Details

On Windows, cmd.exe shims (e.g., those planted by VS Code or npm) can fail when the path contains special characters like (. Since gh copilot invokes the binary via os/exec, these failures surface as opaque errors. This change adds a practical workaround hint so users can still use Copilot CLI directly.

Related to #13106

When the copilot binary is found in PATH but exec fails (e.g., due to
unusual characters like parentheses in the path on Windows), append a
hint suggesting the user run `copilot` directly without `gh`.

The hint is only shown when the binary was already present on the host,
not when it was freshly downloaded and installed by `gh`.

Closes #13106

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 11, 2026 13:35
@babakks babakks requested a review from a team as a code owner May 11, 2026 13:35
Copy link
Copy Markdown
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

Adds a user-facing hint when gh copilot locates an existing copilot executable but fails to execute it (notably on Windows paths containing special characters), guiding users to run copilot directly as a workaround.

Changes:

  • Tracks whether the Copilot CLI was found before attempting download/install and appends a hint to the error message on exec failures.
  • Introduces injectable function variables for finding/running the external binary to enable deterministic testing.
  • Adds a unit test asserting the hint is included and the original exec error remains wrapped.
Show a summary per file
File Description
pkg/cmd/copilot/copilot.go Adds PATH-vs-install detection and appends a workaround hint on exec failures; adds indirection hooks for testing.
pkg/cmd/copilot/copilot_test.go Adds a unit test validating the exec-failure hint behavior via injected hooks.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment on lines +146 to +147
foundInPath := copilotPath != ""
if !foundInPath {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like this is a fair comment, but if we downloaded it and we're failing to execute it, instructing the user to try something like copilot doesn't really hurt anything.

Comment on lines +186 to +189
// The binary exists in PATH but exec failed, possibly due to
// unusual characters in the path (see https://github.com/cli/cli/issues/13106).
// Suggest running copilot directly as a workaround.
return fmt.Errorf("%w\nTry running `copilot` directly without `gh`.", err)
Copy link
Copy Markdown
Member

@BagToad BagToad May 11, 2026

Choose a reason for hiding this comment

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

Suggested change
// The binary exists in PATH but exec failed, possibly due to
// unusual characters in the path (see https://github.com/cli/cli/issues/13106).
// Suggest running copilot directly as a workaround.
return fmt.Errorf("%w\nTry running `copilot` directly without `gh`.", err)
// We found a `copilot` binary but exec failed, possibly due to
// unusual characters in the path (see https://github.com/cli/cli/issues/13106).
// Suggest running copilot directly as a workaround.
return fmt.Errorf("%w\nFailed to run '%s', try running `copilot` directly without `gh`.", err, copilotPath)

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.

3 participants