linera-io/linera-protocol · error

pr_number is None

Error message

pr_number is None

What it means

In local mode, GithubContext::from_env takes commit/branch/base from the local git checkout but still needs a PR number to know which pull request to read and comment on; it has no way to derive one from git. The pr_number parameter is optional at the API boundary, and this error is the explicit refusal when it was not supplied.

Source

Thrown at linera-summary/src/github.rs:116

        };

        // This local mode is only used for testing, so we're just hardcoding `main` as the base branch for now.
        Ok((commit_hash, branch_name, "main".to_string()))
    }

    fn from_env(is_local: bool, pr_number: Option<u64>) -> Result<Self> {
        let env_pr_commit_hash = env::var("GITHUB_PR_COMMIT_HASH");
        let env_pr_branch = env::var("GITHUB_PR_BRANCH");
        let env_base_branch = env::var("GITHUB_BASE_BRANCH");
        let env_pr_number = env::var("GITHUB_PR_NUMBER");

        let (pr_commit_hash, pr_branch, base_branch, pr_number) = if is_local {
            let (commit_hash, branch_name, base) = Self::get_local_git_info()?;
            (
                commit_hash,
                branch_name,
                base,
                pr_number.ok_or_else(|| anyhow!("pr_number is None"))?,
            )
        } else {
            let pr_string = env_pr_number.map_err(|_| {
                anyhow!("GITHUB_PR_NUMBER is not set! This must be run from within CI")
            })?;
            (
                env_pr_commit_hash.map_err(|_| {
                    anyhow!("GITHUB_PR_COMMIT_HASH is not set! This must be run from within CI")
                })?,
                env_pr_branch.map_err(|_| {
                    anyhow!("GITHUB_PR_BRANCH is not set! This must be run from within CI")
                })?,
                env_base_branch.map_err(|_| {
                    anyhow!("GITHUB_BASE_BRANCH is not set! This must be run from within CI")
                })?,
                pr_string
                    .parse()
                    .map_err(|_| anyhow!("GITHUB_PR_NUMBER is not a valid number: {pr_string}"))?,

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Pass the PR number when running locally, e.g. --local --pr-number 1234
  2. If you do not have a PR yet, create one first or run in CI mode where the number comes from GITHUB_PR_NUMBER

Example fix

# before
linera-summary --local
# after
linera-summary --local --pr-number 1234
Defensive patterns

Strategy: validation

Validate before calling

// Rust: require the PR number in local mode before calling
let pr_number = pr_number.context("local mode requires an explicit PR number (--pr-number N)")?;

Type guard

fn local_mode_ready(pr_number: Option<u64>) -> bool { pr_number.is_some() }

Try / catch

if let Err(e) = Github::new(true, pr_number) {
    if e.to_string().contains("pr_number is None") {
        eprintln!("pass --pr-number <N> when running in local mode");
    }
    return Err(e.into());
}

Prevention

When it happens

Trigger: Invoking linera-summary's local mode without the PR-number argument/option, e.g. `--local` with no accompanying pr-number value.

Common situations: Local dry-runs of the summary tool during development; changing CLI wiring so the parsed PR number no longer reaches GithubContext::new.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22). Data as JSON: /api/errors/318f3ada97c09984. Report an issue: GitHub.