{"record":{"id":"6df26cb82a75e1f0","repo":"Hmbown/CodeWhale","slug":"gh-pr-view-number-failed-stderr","errorCode":null,"errorMessage":"gh pr view #{number} failed: {stderr}","messagePattern":"gh pr view #(.+?) failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":8250,"sourceCode":"    head: String,\n    url: String,\n}\n\nfn run_gh_pr_view(number: u32, repo: Option<&str>) -> Result<GhPullRequest> {\n    let mut cmd = crate::dependencies::Gh::command()\n        .ok_or_else(|| anyhow::anyhow!(\"gh not found on PATH\"))?;\n    cmd.arg(\"pr\").arg(\"view\").arg(number.to_string());\n    if let Some(r) = repo {\n        cmd.arg(\"--repo\").arg(r);\n    }\n    cmd.arg(\"--json\")\n        .arg(\"title,body,baseRefName,headRefName,url\");\n    let output = cmd\n        .output()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run `gh pr view`: {e}\"))?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();\n        bail!(\"gh pr view #{number} failed: {stderr}\");\n    }\n    let raw = String::from_utf8_lossy(&output.stdout).to_string();\n    let value: serde_json::Value = serde_json::from_str(&raw)\n        .map_err(|e| anyhow::anyhow!(\"gh pr view returned non-JSON output: {e}\"))?;\n    let pick = |key: &str| {\n        value\n            .get(key)\n            .and_then(serde_json::Value::as_str)\n            .unwrap_or_default()\n            .to_string()\n    };\n    Ok(GhPullRequest {\n        title: pick(\"title\"),\n        body: pick(\"body\"),\n        base: pick(\"baseRefName\"),\n        head: pick(\"headRefName\"),\n        url: pick(\"url\"),\n    })","sourceCodeStart":8232,"sourceCodeEnd":8268,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/lib.rs#L8232-L8268","documentation":"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:\".","triggerScenarios":"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.","commonSituations":"CI token expired between runs; PR closed/deleted or number typo'd; --repo pointing at a fork without that PR; flaky network.","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"],"exampleFix":"// before\n$ codewhale pr 999999\nError: gh pr view #999999 failed: ... Couldn't find PR ...\n\n// after: reproduce raw, then fix the root cause\n$ gh pr view 999999 --json title   # see gh's own error\n$ gh auth status                   # re-auth if that is the cause","handlingStrategy":"try-catch","validationCode":"gh pr view \"$N\" --json url >/dev/null 2>&1 || { echo 'gh cannot view this PR (auth? number? repo?)' >&2; exit 2; }\ncodewhale pr \"$N\"","typeGuard":null,"tryCatchPattern":"if ! out=$(gh pr view \"$N\" --json title 2>gh.err); then\n  echo \"gh pr view #$N failed: $(cat gh.err)\" >&2; exit 1\nfi\ncodewhale pr \"$N\"","preventionTips":["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"],"tags":["github","pr","gh-cli","subprocess","external-error"],"backgroundTag":"external-command-failed","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}