{"record":{"id":"8313013144e7d0c9","repo":"Hmbown/CodeWhale","slug":"gh-pr-diff-number-failed-stderr","errorCode":null,"errorMessage":"gh pr diff #{number} failed: {stderr}","messagePattern":"gh pr diff #(.+?) failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":8283,"sourceCode":"        base: pick(\"baseRefName\"),\n        head: pick(\"headRefName\"),\n        url: pick(\"url\"),\n    })\n}\n\nfn run_gh_pr_diff(number: u32, repo: Option<&str>) -> Result<String> {\n    let mut cmd = crate::dependencies::Gh::command()\n        .ok_or_else(|| anyhow::anyhow!(\"gh not found on PATH\"))?;\n    cmd.arg(\"pr\").arg(\"diff\").arg(number.to_string());\n    if let Some(r) = repo {\n        cmd.arg(\"--repo\").arg(r);\n    }\n    let output = cmd\n        .output()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run `gh pr diff`: {e}\"))?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n        bail!(\"gh pr diff #{number} failed: {stderr}\");\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).to_string())\n}\n\nfn run_gh_pr_checkout(number: u32, repo: Option<&str>) -> Result<()> {\n    let mut cmd = crate::dependencies::Gh::command()\n        .ok_or_else(|| anyhow::anyhow!(\"gh not found on PATH\"))?;\n    cmd.arg(\"pr\").arg(\"checkout\").arg(number.to_string());\n    if let Some(r) = repo {\n        cmd.arg(\"--repo\").arg(r);\n    }\n    let output = cmd\n        .output()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run `gh pr checkout`: {e}\"))?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n        bail!(\"gh pr checkout #{number} failed: {stderr}\");\n    }","sourceCodeStart":8265,"sourceCodeEnd":8301,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/lib.rs#L8265-L8301","documentation":"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\").","triggerScenarios":"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).","commonSituations":"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.","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`)"],"exampleFix":"# before\ncodewhale review --pr 4242 --repo owner/private-repo\n# gh pr diff #4242 failed: Could not resolve to a PullRequest\n\n# after\ngh auth status && gh pr view 4242 --repo owner/private-repo   # pre-flight passes\ncodewhale review --pr 4242 --repo owner/private-repo","handlingStrategy":"validation","validationCode":"gh auth status >/dev/null 2>&1 || { echo 'gh not authenticated'; exit 1; }\ngh pr view \"$PR\" ${REPO:+--repo \"$REPO\"} --json number >/dev/null 2>&1 || { echo \"PR $PR not visible\"; exit 1; }","typeGuard":null,"tryCatchPattern":"match run_gh_pr_diff(number, repo.as_deref()) {\n    Ok(diff) => { /* use diff */ }\n    Err(e) => eprintln!(\"gh pr diff failed: {e:#}\"), // gh's stderr is embedded; act on it, do not blind-retry\n}","preventionTips":["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"],"tags":["gh-cli","subprocess","pull-request","github","auth"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}