gitbutlerapp/gitbutler · error

GitHub GraphQL pull request #

Error message

GitHub GraphQL pull request #{pr_number} not found for {owner}/{repo}

What it means

The repository resolved in GraphQL but repository.pull_request(number: pr_number) was null — no pull request with that number exists (or is visible to the token) in that repository. Note GitHub shares the issue/PR number space, so a number can exist as an issue without being a PR.

Solutions

  1. Verify the number is a pull request, not an issue (GitHub numbers both in one sequence): check github.com/{owner}/{repo}/pull/{n}
  2. Confirm the PR belongs to the same owner/repo passed to the API
  3. Re-fetch the current PR number — the PR may have been closed and the automation config is stale
  4. Ensure the token can see the repository's PRs (private repo access/SSO)

Example fix

// before
let pr_number = 42; // actually an issue number
// after
let pr_number = 57; // correct PR number verified via gh pr list
Defensive patterns

Strategy: validation

Validate before calling

// verify the number is really a PR in this repo before mutating
let pr = client.get_pull_request(owner, repo, pr_number).await?; // errors early if it's an issue or missing

Try / catch

match client.get_pull_request_node_id(owner, repo, pr_number).await {
    Err(e) if e.to_string().contains("not found") => {
        eprintln!("#{pr_number} is not a pull request in {owner}/{repo} — check issue vs PR number");
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling get_pull_request_node_id (directly or via set_pull_request_draft_state / auto-merge APIs) with a PR number that is actually an issue number, a closed-and-doesn't-exist number, or a number from a different repository.

Common situations: Copying a number from an issue tracker ticket that doesn't match the PR number; referring to a PR in a fork rather than the upstream repo; PR number from stale config after branch cleanup; token can't see PRs from a private repo.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/90b878f7062708ea. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-github/src/client.rs:1779

        }

        let data: QueryData = self
            .graphql_query(
                GQL_GET_PR_NODE_ID,
                &Variables {
                    owner,
                    repo,
                    number: pr_number,
                },
            )
            .await?;

        let Some(repository) = data.repository else {
            bail!("GitHub GraphQL repository not found for {owner}/{repo}");
        };

        let Some(pull_request) = repository.pull_request else {
            bail!("GitHub GraphQL pull request #{pr_number} not found for {owner}/{repo}",);
        };

        if pull_request.id.is_empty() {
            bail!(
                "GitHub GraphQL pull request #{pr_number} in {owner}/{repo} returned an empty node id",
            );
        }

        Ok(PullRequestNodeId::from_string(pull_request.id))
    }

    async fn graphql_query<T, V>(&self, query: &str, variables: &V) -> Result<T>
    where
        T: for<'de> Deserialize<'de>,
        V: Serialize,
    {
        #[derive(Serialize)]
        struct GraphQlRequest<'a, V> {

View on GitHub (pinned to 58e5313667)