vectordotdev/vector · error

Failed to create PR with gh CLI

Error message

Failed to create PR with gh CLI

What it means

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.

Solutions

  1. Run `gh auth status` and re-authenticate if needed (`gh auth login`), ensuring the token has repo scope.
  2. Run the underlying `gh pr create ...` command manually to see gh's stderr for the exact failure (auth, permissions, or existing PR).
  3. If a PR already exists for the branch, close/skip it or reuse the existing PR instead of re-running open_release_pr.
  4. Verify you can push the branch (`git push origin <branch>`) before creating the PR.

Example fix

// before
$ gh pr create ...   # gh: not logged in
// after
$ gh auth login && vdev release prepare
Defensive patterns

Strategy: try-catch

Validate before calling

let ok = std::process::Command::new("gh")
    .args(["auth", "status"])
    .status()
    .map(|s| s.success())
    .unwrap_or(false);
assert!(ok, "gh CLI must be authenticated before release prepare");

Try / catch

match gh_pr_create() {
    Ok(_) => /* proceed */,
    Err(e) => eprintln!("run `gh auth login` or check for an existing PR: {e}"),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@0d4ab78a4f (2026-09-16). Data as JSON: /api/errors/5d4d1a7a61506340. Report an issue: GitHub.

Appendix: source

Thrown at vdev/src/commands/release/prepare.rs:214

        let pr_body = format!("This PR prepares the release for Vector v{new_vector_version}");
        let gh_status = Command::new("gh")
            .arg("pr")
            .arg("create")
            .arg("--draft")
            .arg("--base")
            .arg(self.release_branch.as_str())
            .arg("--head")
            .arg(self.release_preparation_branch.as_str())
            .arg("--title")
            .arg(&pr_title)
            .arg("--body")
            .arg(&pr_body)
            .arg("--label")
            .arg("no-changelog")
            .current_dir(&self.repo_root)
            .status()?;
        if !gh_status.success() {
            return Err(anyhow!("Failed to create PR with gh CLI"));
        }
        info!("Successfully created PR against {}", self.release_branch);
        Ok(())
    }

    fn append_vrl_changelog_to_release_cue(&self) -> Result<()> {
        debug!("append_vrl_changelog_to_release_cue");

        let releases_path = self.repo_root.join("website/cue/reference/releases");
        let version = &self.new_vector_version;
        let cue_path = releases_path.join(format!("{version}.cue"));
        if !cue_path.is_file() {
            return Err(anyhow!("{} not found", cue_path.display()));
        }

        let vrl_changelog = get_vrl_changelog(&self.vrl_version)?;
        let vrl_changelog_block = format_vrl_changelog_block(&vrl_changelog);

View on GitHub (pinned to 0d4ab78a4f)