{"record":{"id":"70ddb8cfdb104528","repo":"Hmbown/CodeWhale","slug":"gh-pr-checkout-number-failed-stderr","errorCode":null,"errorMessage":"gh pr checkout #{number} failed: {stderr}","messagePattern":"gh pr checkout #(.+?) failed: (.+?)","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9291,"sourceCode":"}\n\nfn run_gh_pr_diff(number: u32, repo: Option<&str>, view: &GhPullRequest) -> Result<String> {\n    crate::tools::review_pr::fetch_diff(number, repo, &std::env::current_dir()?, view)\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    }\n    Ok(())\n}\n\n/// Resolve the `owner/name` repository `gh` believes the current workspace\n/// belongs to. `gh api` needs an explicit repository path, unlike `gh pr`\n/// which infers it from the working directory.\nfn run_gh_repo_name() -> Result<String> {\n    let mut cmd = crate::dependencies::Gh::command()\n        .ok_or_else(|| anyhow::anyhow!(\"gh not found on PATH\"))?;\n    cmd.arg(\"repo\")\n        .arg(\"view\")\n        .arg(\"--json\")\n        .arg(\"nameWithOwner\")\n        .arg(\"--jq\")\n        .arg(\".nameWithOwner\");\n    let output = cmd\n        .output()","sourceCodeStart":9273,"sourceCodeEnd":9309,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L9273-L9309","documentation":"The wrapper running `gh pr checkout <number>` found the command exited non-zero. The gh stderr is trimmed and embedded in the error so the underlying GitHub failure (auth, missing PR, dirty worktree) is visible. Spawn failures surface separately as \"Failed to run `gh pr checkout`\".","triggerScenarios":"Calling the PR checkout path when `gh pr checkout` fails: PR number does not exist or is inaccessible, `gh` is not authenticated, or the current git worktree has local changes blocking checkout.","commonSituations":"Typo in the PR number; private-repo PR without `gh auth login`; checking out while the working directory has uncommitted changes that would be overwritten; detached fork setups gh cannot resolve.","solutions":["Read the embedded stderr and fix the gh-reported cause (wrong PR number, dirty worktree, auth)","Run `gh auth status` / `gh auth login` to confirm authentication and repo access","Commit, stash, or clean local changes before checkout (`git stash`)","Verify the PR exists and is visible: `gh pr view <number>`"],"exampleFix":"// before\ncodewhale pr 999999   # gh: no pull requests found\n// after\ncodewhale pr 123      # valid, accessible PR number","handlingStrategy":"try-catch","validationCode":"gh pr view \"$PR\" --json number >/dev/null 2>&1 || { echo \"PR $PR not accessible\"; exit 1; }\ngit diff --quiet || { echo 'worktree dirty; commit or stash first'; exit 1; }","typeGuard":null,"tryCatchPattern":"// run the command, capture stderr; the codewhale error embeds gh's stderr — surface it verbatim\nconst { status, stderr } = spawnSync('gh', ['pr', 'checkout', String(n)]);\nif (status !== 0) throw new Error(`gh pr checkout #${n} failed: ${stderr.trim()}`);","preventionTips":["Confirm the PR number with `gh pr view` before checkout","Keep the worktree clean before automated checkouts","Ensure gh is authenticated for the target repo"],"tags":["cli","gh","git","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}