{"record":{"id":"b6101893dfe1ae87","repo":"Hmbown/CodeWhale","slug":"gh-pr-create-failed","errorCode":null,"errorMessage":"gh pr create failed: {}","messagePattern":"gh pr create failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/dispatch_runner.rs","lineNumber":606,"sourceCode":"    body: &str,\n) -> Result<String> {\n    let body_dir = tempfile::tempdir().context(\"could not stage the PR body\")?;\n    let body_file = body_dir.path().join(\"body.md\");\n    std::fs::write(&body_file, body).context(\"could not write the PR body\")?;\n    let mut command = crate::dependencies::Gh::command()\n        .ok_or_else(|| anyhow!(\"the GitHub pull request needs the gh CLI on PATH\"))?;\n    command.args(gh_pr_create_argv(\n        slug,\n        &patch.base_branch,\n        &job.branch,\n        title,\n        &body_file.to_string_lossy(),\n    ));\n    let output = command\n        .output()\n        .context(\"failed to start gh for the pull request\")?;\n    if !output.status.success() {\n        bail!(\n            \"gh pr create failed: {}\",\n            sanitize_error(&String::from_utf8_lossy(&output.stderr))\n        );\n    }\n    let url = String::from_utf8_lossy(&output.stdout).trim().to_string();\n    if !url.starts_with(\"https://\") {\n        bail!(\"gh did not report a pull request URL; refusing to invent one.\");\n    }\n    Ok(url)\n}\n\nfn open_pr_gitee(\n    slug: &str,\n    job: &CloudJob,\n    patch: &PatchReceipt,\n    title: &str,\n    body: &str,\n) -> Result<String> {","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/dispatch_runner.rs#L588-L624","documentation":"open_pr_github wraps a failing `gh pr create` invocation; the formatted error carries gh's failure output so a rejected PR creation (auth, branch protection, bad slug) is attributable to its cause rather than surfacing as an empty exit code.","triggerScenarios":"open (via open_pr_github) runs `gh pr create` and the process exits nonzero — auth problems, no GitHub remote, PR already exists, template/base-branch issues.","commonSituations":"gh CLI not authenticated (GH_TOKEN missing or expired), repository has no GitHub origin, a PR already exists for the branch, blocked-by-rules base branch, or gh version too old.","solutions":["Check gh stderr in the error; run `gh auth status` and re-authenticate if needed","Verify the repo remote points at GitHub and you have push/PR rights","Check if a PR for the branch already exists (`gh pr list --head <branch>`)","Update the gh CLI and retry"],"exampleFix":"// before\n// gh pr create failed: gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable\n// after\nexport GH_TOKEN=$(gh auth token)\n# or locally:\ngh auth login","handlingStrategy":"retry","validationCode":"let auth = Command::new(\"gh\").args([\"auth\",\"status\"]).output()?;\nif !auth.status.success() { /* run gh auth login first */ }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"gh pr create failed\") => {\n        // inspect sanitized stderr: re-auth, check existing PR, retry\n    }\n    other => other?,\n}","preventionTips":["Run `gh auth status` before dispatch workflows","Check for an existing PR on the branch before creating one","Keep the gh CLI updated"],"tags":["github","cli","pull-request","process"],"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"}