Hmbown/CodeWhale · error · anyhow::Error
gh pr view #{number} failed: {stderr}
Error message
gh pr view #{number} failed: {stderr} What it means
run_gh_pr_view() executes `gh pr view <N> [--repo R] --json title,body,baseRefName,headRefName,url` and bails with gh's stderr when the subprocess exits non-zero. The message is a pass-through: whatever gh reported — authentication required, PR not found, no repository access, network failure, rate limiting — appears verbatim after "gh pr view #N failed:".
Source
Thrown at crates/tui/src/lib.rs:8250
head: String,
url: String,
}
fn run_gh_pr_view(number: u32, repo: Option<&str>) -> Result<GhPullRequest> {
let mut cmd = crate::dependencies::Gh::command()
.ok_or_else(|| anyhow::anyhow!("gh not found on PATH"))?;
cmd.arg("pr").arg("view").arg(number.to_string());
if let Some(r) = repo {
cmd.arg("--repo").arg(r);
}
cmd.arg("--json")
.arg("title,body,baseRefName,headRefName,url");
let output = cmd
.output()
.map_err(|e| anyhow::anyhow!("Failed to run `gh pr view`: {e}"))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
bail!("gh pr view #{number} failed: {stderr}");
}
let raw = String::from_utf8_lossy(&output.stdout).to_string();
let value: serde_json::Value = serde_json::from_str(&raw)
.map_err(|e| anyhow::anyhow!("gh pr view returned non-JSON output: {e}"))?;
let pick = |key: &str| {
value
.get(key)
.and_then(serde_json::Value::as_str)
.unwrap_or_default()
.to_string()
};
Ok(GhPullRequest {
title: pick("title"),
body: pick("body"),
base: pick("baseRefName"),
head: pick("headRefName"),
url: pick("url"),
})View on GitHub (pinned to 0c42157ee5)
Solutions
- Run `gh pr view <N> --json title` yourself to see gh's raw error
- Check auth: `gh auth status`, re-auth with `gh auth login` if expired
- Verify the PR number exists and you have access (`gh pr list` or the browser)
- In automation, pin `--repo owner/name` and use a fresh token
Example fix
// before $ codewhale pr 999999 Error: gh pr view #999999 failed: ... Couldn't find PR ... // after: reproduce raw, then fix the root cause $ gh pr view 999999 --json title # see gh's own error $ gh auth status # re-auth if that is the cause
Defensive patterns
Strategy: try-catch
Validate before calling
gh pr view "$N" --json url >/dev/null 2>&1 || { echo 'gh cannot view this PR (auth? number? repo?)' >&2; exit 2; }
codewhale pr "$N" Try / catch
if ! out=$(gh pr view "$N" --json title 2>gh.err); then echo "gh pr view #$N failed: $(cat gh.err)" >&2; exit 1 fi codewhale pr "$N"
Prevention
- Run `gh auth status` in CI preflight and rotate tokens on a schedule
- Pass --repo explicitly in automation so the checkout's remote cannot misroute the query
- Validate PR numbers before invoking codewhale pr
When it happens
Trigger: gh exits non-zero: expired or missing auth, a PR number that does not exist in the target repo, a wrong or inaccessible --repo, gh-side network failures, or rate limiting.
Common situations: CI token expired between runs; PR closed/deleted or number typo'd; --repo pointing at a fork without that PR; flaky network.
Related errors
- `gh` CLI not found on PATH. Install GitHub CLI (https://cli.
- gh pr diff #{number} failed: {stderr}
- gh pr checkout #{number} failed: {stderr}
- NotFound
- release redirect did not resolve to a tag URL: {final_url}
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/6df26cb82a75e1f0.
Report an issue: GitHub.