Skip to content

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

Merged
babakks merged 3 commits into
trunkfrom
babakks/improve-gh-copilot-error
May 12, 2026
Merged

fix(copilot): hint to run copilot directly when exec fails#13393
babakks merged 3 commits 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 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:

Failed to run '<path>', try running `copilot` directly without `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 thread pkg/cmd/copilot/copilot.go Outdated
Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
@babakks babakks enabled auto-merge May 12, 2026 11:24
@babakks
Copy link
Copy Markdown
Member Author

babakks commented May 12, 2026

@copilot fix the failing test

auto-merge was automatically disabled May 12, 2026 13:04

Head branch was pushed to by a user without write access

Copy link
Copy Markdown
Contributor

Copilot AI commented May 12, 2026

@copilot fix the failing test

Fixed in the latest commit. The test was checking for "Try running \copilot` directly without `gh`."(capital T) but the error message had been updated per the accepted suggestion to use lowercase"try running..."`. Updated the assertion to match.

@babakks babakks enabled auto-merge May 12, 2026 13:05
@babakks babakks merged commit fe996d3 into trunk May 12, 2026
18 checks passed
@babakks babakks deleted the babakks/improve-gh-copilot-error branch May 12, 2026 13:14
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.

4 participants