denoland/deno · error · AnyError

Failed to find PR #{pr_number}: {stderr}

Error message

Failed to find PR #{pr_number}: {stderr}

What it means

After confirming gh exists, Deno runs `gh pr view <n> --repo denoland/deno --json ...` to fetch the PR's title, state, branch, and head SHA. If gh exits non-zero, Deno bails with 'Failed to find PR' plus gh's stderr. The stderr text is the real diagnosis: unknown PR number, no authentication, no network, or permission problems.

Source

Thrown at cli/tools/upgrade.rs:642

  // Verify the PR exists and get its title/state/branch
  let pr_info = Command::new("gh")
    .args([
      "pr",
      "view",
      &pr_number.to_string(),
      "--repo",
      "denoland/deno",
      "--json",
      "title,state,headRefName,headRefOid",
      "-q",
      r#"[.title, .state, .headRefName, .headRefOid] | @tsv"#,
    ])
    .output()
    .context("failed to run `gh pr view`")?;

  if !pr_info.status.success() {
    let stderr = String::from_utf8_lossy(&pr_info.stderr);
    bail!("Failed to find PR #{pr_number}: {stderr}");
  }

  let pr_info_str = String::from_utf8_lossy(&pr_info.stdout);
  let pr_fields: Vec<&str> = pr_info_str.trim().splitn(4, '\t').collect();
  let pr_title = pr_fields.first().unwrap_or(&"unknown");
  let pr_state = pr_fields.get(1).unwrap_or(&"unknown");
  let pr_branch = pr_fields.get(2).unwrap_or(&"");
  let pr_head_sha = pr_fields.get(3).unwrap_or(&"");

  log::info!(
    "PR #{}: {} ({})",
    pr_number,
    colors::bold(pr_title),
    pr_state
  );

  let artifact_name = get_pr_artifact_name()?;
  let debug_artifact_name = get_pr_debug_artifact_name()?;

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Run `gh pr view <n> --repo denoland/deno` yourself and read the stderr Deno printed — it states the exact cause.
  2. Fix authentication: `gh auth login` (or `gh auth status` to inspect the current token).
  3. Confirm the number is a real PR (not an issue) in denoland/deno and retry with the correct ID.
  4. If it is a network/proxy problem, fix connectivity to github.com/api.github.com and retry.

Example fix

# before
deno upgrade --pr 1234  # typo, PR does not exist

# after
deno upgrade --pr 12345  # verify via: gh pr view 12345 --repo denoland/deno
Defensive patterns

Strategy: try-catch

Validate before calling

gh pr view 12345 --repo denoland/deno --json state >/dev/null 2>&1 || { echo "PR missing or gh not authed"; exit 1; }
deno upgrade --pr 12345

Try / catch

if ! deno upgrade --pr 12345 2>err.log; then grep -q 'Failed to find PR' err.log && cat err.log; fi

Prevention

When it happens

Trigger: `deno upgrade --pr <n>` where the PR number does not exist in denoland/deno; gh has no valid token (`gh auth login` not run or expired); GitHub is unreachable; the `gh pr view` invocation itself fails (bad gh version missing --json/-q support).

Common situations: Typos in the PR number; referencing an issue number instead of a PR number; CI/container environments where gh is installed but unauthenticated; corporate proxies blocking api.github.com.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/e825f444ed1ad874. Report an issue: GitHub.