{"record":{"id":"3ba5929fc0db4570","repo":"affaan-m/ECC","slug":"gh-pr-create-failed-stderr","errorCode":null,"errorMessage":"gh pr create failed: {stderr}","messagePattern":"gh pr create failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/worktree/mod.rs","lineNumber":598,"sourceCode":"        .filter(|value| !value.is_empty())\n    {\n        command.arg(\"--label\").arg(label);\n    }\n    for reviewer in options\n        .reviewers\n        .iter()\n        .map(|value| value.trim())\n        .filter(|value| !value.is_empty())\n    {\n        command.arg(\"--reviewer\").arg(reviewer);\n    }\n    let output = command\n        .current_dir(&worktree.path)\n        .output()\n        .context(\"Failed to create draft PR with gh\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"gh pr create failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())\n}\n\nfn git_remote_origin_url(repo_root: &Path) -> Result<String> {\n    let output = Command::new(\"git\")\n        .arg(\"-C\")\n        .arg(repo_root)\n        .args([\"remote\", \"get-url\", \"origin\"])\n        .output()\n        .context(\"Failed to resolve git origin remote\")?;\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"git remote get-url origin failed: {stderr}\");\n    }\n\n    Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/worktree/mod.rs#L580-L616","documentation":"create_draft_pr_with_gh runs `gh pr create` inside the worktree to open a draft pull request. When gh exits nonzero, the library bails with gh's stderr so the GitHub-side failure (GraphQL error, missing auth, invalid base, etc.) is visible in the message.","triggerScenarios":"Calling create_draft_pr when `gh` is unauthenticated, the base branch named in DraftPrOptions does not exist on the remote, the branch is already covered by an open PR, GitHub returns a validation error, or gh CLI is a version lacking a used flag.","commonSituations":"CI without `gh auth login` / GH_TOKEN set; typo'd custom base branch or nonexistent labels/reviewers passed in options; `draft PR already exists` after a retry; corporate proxy blocking api.github.com.","solutions":["Read the stderr in the message — gh prints the exact GitHub API error.","Run `gh auth status` in the worktree environment and authenticate (GH_TOKEN or `gh auth login`).","Verify the base branch and any labels/reviewers exist on the remote before calling.","Check for an existing open PR for the branch (`gh pr list --head <branch>`).","Update the gh CLI if the error mentions an unknown flag."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let auth = Command::new(\"gh\").args([\"auth\", \"status\"]).output()?;\nif !auth.status.success() { eprintln!(\"gh not authenticated\"); }","typeGuard":null,"tryCatchPattern":"match create_draft_pr(&wt, title, body) {\n    Ok(url) => println!(\"draft PR: {url}\"),\n    Err(e) if e.to_string().contains(\"already exists\") => eprintln!(\"PR already open\"),\n    Err(e) if e.to_string().contains(\"auth\") => eprintln!(\"run: gh auth login or set GH_TOKEN\"),\n    Err(e) => return Err(e),\n}","preventionTips":["Authenticate gh (GH_TOKEN or gh auth login) in the execution environment","Verify custom base branches, labels, and reviewers exist on the remote","Check for an existing PR for the branch before retrying","Keep the gh CLI updated"],"tags":["github","gh-cli","pr","network"],"backgroundTag":"api-error-response","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}