nikivdev/code · error

failed to determine PR URL after creation (gh output had no

Error message

failed to determine PR URL after creation (gh output had no URL and PR lookup by head returned empty)

What it means

Raised in `gh_create_pr` (src/commit.rs:8917) when `gh pr create` SUCCEEDED but the tool could not determine the new PR's URL: neither the gh output contained a URL nor a follow-up lookup of an open PR for the same head branch (`gh_find_open_pr_by_head`) returned anything. The PR was likely created; only its URL/number could not be resolved.

Source

Thrown at src/commit.rs:8917

        bail!(
            "gh {} failed: {}",
            args.join(" "),
            String::from_utf8_lossy(&output.stderr).trim()
        );
    }

    // gh typically prints the PR URL, but some versions/configs can produce no stdout.
    if let Some(url) = extract_pr_url(&combined) {
        let number = pr_number_from_url(&url)
            .ok_or_else(|| anyhow::anyhow!("failed to parse PR number from URL {}", url))?;
        return Ok((number, url));
    }

    if let Some(found) = gh_find_open_pr_by_head(repo_root, repo, head)? {
        return Ok(found);
    }

    bail!(
        "failed to determine PR URL after creation (gh output had no URL and PR lookup by head returned empty)"
    );
}

fn open_in_browser(url: &str) -> Result<()> {
    #[cfg(target_os = "macos")]
    {
        let status = Command::new("open").arg(url).status()?;
        if !status.success() {
            bail!("failed to open browser");
        }
        return Ok(());
    }

    #[cfg(not(target_os = "macos"))]
    {
        let status = Command::new("xdg-open").arg(url).status()?;
        if !status.success() {

View on GitHub (pinned to a747e741ae)

Solutions

  1. Upgrade gh (`gh upgrade` or package manager) so `gh pr create` prints the PR URL.
  2. Check GitHub manually for the PR on the head branch to confirm it was created.
  3. Run `gh pr list --head <branch> --json url` and verify head string format (try `owner:branch`).
  4. Ensure the gh token can list PRs in the target repo.
  5. Retry idempotently: since a PR may already exist, re-running the flow usually recovers the URL via the already-exists path.

Example fix

// before: head passed as plain branch, lookup misses 'owner:branch' PRs
let pr = gh_create_pr(root, "org/repo", "feature-x", "main", ...)?;
// after
let pr = gh_create_pr(root, "org/repo", "org:feature-x", "main", ...)?;
Defensive patterns

Strategy: fallback

Validate before calling

let v = Command::new("gh").arg("--version").output()?;
println!("gh version: {}", String::from_utf8_lossy(&v.stdout));
let out = Command::new("gh").args(["pr","list","--repo",repo,"--head",head,"--json","url"])
    .current_dir(repo_root).output()?;
if !out.status.success() { bail!("cannot list PRs for head: check token scope"); }

Type guard

fn pr_url_present(stdout: &str, stderr: &str) -> Option<String> {
    let combined = format!("{}\n{}", stdout, stderr);
    combined.lines().map(str::trim)
        .find(|l| l.starts_with("http") && l.contains("/pull/"))
        .map(String::from)
}

Try / catch

match create_pr_and_open(...) {
    Ok(pr) => use_pr(pr),
    Err(e) if e.to_string().contains("failed to determine PR URL") => {
        // PR was likely created; recover by listing PRs for the head branch
        let url = gh_pr_list_by_head(repo, head)?;
        eprintln!("recovered PR URL by lookup: {url}");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: gh exits 0 but prints no URL (older gh versions, non-tty output, alternate config), and the head-based open-PR lookup returns empty because the repo/head strings don't match how GitHub lists the PR.

Common situations: Outdated gh CLI whose stdout omits the URL; `head` passed in a different format than GitHub reports (e.g. 'branch' vs 'owner:branch'); permission/scope restrictions so the head lookup can't see the PR; rate limiting on the follow-up lookup.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/ebf797af3905654f. Report an issue: GitHub.