{"record":{"id":"5d4d1a7a61506340","repo":"vectordotdev/vector","slug":"failed-to-create-pr-with-gh-cli","errorCode":null,"errorMessage":"Failed to create PR with gh CLI","messagePattern":"Failed to create PR with gh CLI","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"vdev/src/commands/release/prepare.rs","lineNumber":214,"sourceCode":"        let pr_body = format!(\"This PR prepares the release for Vector v{new_vector_version}\");\n        let gh_status = Command::new(\"gh\")\n            .arg(\"pr\")\n            .arg(\"create\")\n            .arg(\"--draft\")\n            .arg(\"--base\")\n            .arg(self.release_branch.as_str())\n            .arg(\"--head\")\n            .arg(self.release_preparation_branch.as_str())\n            .arg(\"--title\")\n            .arg(&pr_title)\n            .arg(\"--body\")\n            .arg(&pr_body)\n            .arg(\"--label\")\n            .arg(\"no-changelog\")\n            .current_dir(&self.repo_root)\n            .status()?;\n        if !gh_status.success() {\n            return Err(anyhow!(\"Failed to create PR with gh CLI\"));\n        }\n        info!(\"Successfully created PR against {}\", self.release_branch);\n        Ok(())\n    }\n\n    fn append_vrl_changelog_to_release_cue(&self) -> Result<()> {\n        debug!(\"append_vrl_changelog_to_release_cue\");\n\n        let releases_path = self.repo_root.join(\"website/cue/reference/releases\");\n        let version = &self.new_vector_version;\n        let cue_path = releases_path.join(format!(\"{version}.cue\"));\n        if !cue_path.is_file() {\n            return Err(anyhow!(\"{} not found\", cue_path.display()));\n        }\n\n        let vrl_changelog = get_vrl_changelog(&self.vrl_version)?;\n        let vrl_changelog_block = format_vrl_changelog_block(&vrl_changelog);\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/vectordotdev/vector/blob/0d4ab78a4f0d9c9e5d03a50108a2ae4d2f4b2460/vdev/src/commands/release/prepare.rs#L196-L232","documentation":"open_release_pr shells out to `gh pr create` (with --label no-changelog) via Command::status(). A non-zero exit status — the PR could not be created — produces this generic error, after which the release preparation aborts.","triggerScenarios":"Prepare::run calls open_release_pr while `gh` is not authenticated (`gh auth status` fails), lacks the `repo` scope, the release branch/push fails, or a PR for the branch already exists, causing gh to exit non-zero.","commonSituations":"Running locally without `gh auth login`; expired GitHub token; creating a PR whose branch was already merged/PR already open; missing permission to push the release branch to the remote.","solutions":["Run `gh auth status` and re-authenticate if needed (`gh auth login`), ensuring the token has repo scope.","Run the underlying `gh pr create ...` command manually to see gh's stderr for the exact failure (auth, permissions, or existing PR).","If a PR already exists for the branch, close/skip it or reuse the existing PR instead of re-running open_release_pr.","Verify you can push the branch (`git push origin <branch>`) before creating the PR."],"exampleFix":"// before\n$ gh pr create ...   # gh: not logged in\n// after\n$ gh auth login && vdev release prepare","handlingStrategy":"try-catch","validationCode":"let ok = std::process::Command::new(\"gh\")\n    .args([\"auth\", \"status\"])\n    .status()\n    .map(|s| s.success())\n    .unwrap_or(false);\nassert!(ok, \"gh CLI must be authenticated before release prepare\");","typeGuard":null,"tryCatchPattern":"match gh_pr_create() {\n    Ok(_) => /* proceed */,\n    Err(e) => eprintln!(\"run `gh auth login` or check for an existing PR: {e}\"),\n}","preventionTips":["Run `gh auth login` and `gh auth status` before starting release preparation","Check for an existing open PR on the release branch before creating one","Ensure the GitHub token has repo scope and push rights to the remote"],"tags":["rust","github-cli","release"],"backgroundTag":"git-command-failed","analyzedSha":"0d4ab78a4f0d9c9e5d03a50108a2ae4d2f4b2460","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}