Hmbown/CodeWhale · error · anyhow::Error
gh pr diff #{number} failed: {stderr}
Error message
gh pr diff #{number} failed: {stderr} What it means
run_gh_pr_diff shells out to `gh pr diff <number>` (optionally with `--repo owner/name`) and bails with gh's trimmed stderr when gh exits non-zero. The failure comes from the GitHub CLI itself -- authentication, network, repository, or PR-number problems -- not from codewhale. A missing gh binary is a separate, earlier error ("gh not found on PATH").
Source
Thrown at crates/tui/src/lib.rs:8283
base: pick("baseRefName"),
head: pick("headRefName"),
url: pick("url"),
})
}
fn run_gh_pr_diff(number: u32, repo: Option<&str>) -> Result<String> {
let mut cmd = crate::dependencies::Gh::command()
.ok_or_else(|| anyhow::anyhow!("gh not found on PATH"))?;
cmd.arg("pr").arg("diff").arg(number.to_string());
if let Some(r) = repo {
cmd.arg("--repo").arg(r);
}
let output = cmd
.output()
.map_err(|e| anyhow::anyhow!("Failed to run `gh pr diff`: {e}"))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
bail!("gh pr diff #{number} failed: {stderr}");
}
Ok(String::from_utf8_lossy(&output.stdout).to_string())
}
fn run_gh_pr_checkout(number: u32, repo: Option<&str>) -> Result<()> {
let mut cmd = crate::dependencies::Gh::command()
.ok_or_else(|| anyhow::anyhow!("gh not found on PATH"))?;
cmd.arg("pr").arg("checkout").arg(number.to_string());
if let Some(r) = repo {
cmd.arg("--repo").arg(r);
}
let output = cmd
.output()
.map_err(|e| anyhow::anyhow!("Failed to run `gh pr checkout`: {e}"))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
bail!("gh pr checkout #{number} failed: {stderr}");
}View on GitHub (pinned to 0c42157ee5)
Solutions
- Run `gh auth status` (then `gh auth login` if needed) and retry
- Verify the PR resolves: `gh pr view <number> [--repo owner/name]`
- Read the stderr embedded in the message -- gh states the exact reason (not found, unauthorized, rate limit)
- If behind a proxy, export HTTPS_PROXY/HTTP_PROXY and confirm `gh api user` works
- Confirm gh is on PATH and current (`gh --version`)
Example fix
# before codewhale review --pr 4242 --repo owner/private-repo # gh pr diff #4242 failed: Could not resolve to a PullRequest # after gh auth status && gh pr view 4242 --repo owner/private-repo # pre-flight passes codewhale review --pr 4242 --repo owner/private-repo
Defensive patterns
Strategy: validation
Validate before calling
gh auth status >/dev/null 2>&1 || { echo 'gh not authenticated'; exit 1; }
gh pr view "$PR" ${REPO:+--repo "$REPO"} --json number >/dev/null 2>&1 || { echo "PR $PR not visible"; exit 1; } Try / catch
match run_gh_pr_diff(number, repo.as_deref()) {
Ok(diff) => { /* use diff */ }
Err(e) => eprintln!("gh pr diff failed: {e:#}"), // gh's stderr is embedded; act on it, do not blind-retry
} Prevention
- Authenticate gh on every machine and CI image (gh auth login or GH_TOKEN)
- Pre-resolve PR numbers with `gh pr list --json number` before scripting review loops
- Always pass --repo explicitly in automation to avoid context mismatches
When it happens
Trigger: Invoking the PR review flow that calls run_gh_pr_diff when `gh auth` is expired or absent; `--repo` pointing at a repo that has no PR with that number; a typo'd or cross-repo PR number; gh unable to reach api.github.com (offline, DNS, proxy).
Common situations: Fresh machine or CI runner where gh is installed but never authenticated; expired GH_TOKEN/GITHUB_TOKEN; --repo slug typo; corporate proxy blocking HTTPS; very old gh versions.
Related errors
- gh pr view #{number} failed: {stderr}
- gh pr checkout #{number} failed: {stderr}
- `gh` CLI not found on PATH. Install GitHub CLI (https://cli.
- NotFound
- Kimi is API-key-only in Codewhale. Create a key at https://p
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/8313013144e7d0c9.
Report an issue: GitHub.