linera-io/linera-protocol · error

Creating Octocrab instance should not fail!

Error message

Creating Octocrab instance should not fail!

What it means

Github::new builds an Octocrab client and calls .build() on the builder; if builder configuration is invalid (malformed auth header, invalid HTTP/TLS client configuration injected before build), the future resolves to Err and this anyhow message replaces the underlying octocrab::Error. Note the map_err discards the real cause, so the original error text is lost.

Source

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

    octocrab: Octocrab,
    context: GithubContext,
    is_local: bool,
}

impl Github {
    /// Builds a client from the environment, in local or CI mode, for the given PR number.
    pub fn new(is_local: bool, pr_number: Option<u64>) -> Result<Self> {
        let octocrab_builder = Octocrab::builder();
        let octocrab =
            if is_local {
                octocrab_builder
            } else {
                octocrab_builder.personal_token(env::var("GITHUB_TOKEN").map_err(|_| {
                    anyhow!("GITHUB_TOKEN is not set! This must be run from within CI")
                })?)
            }
            .build()
            .map_err(|_| anyhow!("Creating Octocrab instance should not fail!"))?;

        Ok(Self {
            octocrab,
            context: GithubContext::from_env(is_local, pr_number)?,
            is_local,
        })
    }

    /// Returns the PR context this client is bound to.
    pub fn context(&self) -> &GithubContext {
        &self.context
    }

    /// Updates the tool's existing summary comment on the PR, or creates one if absent.
    pub async fn upsert_pr_comment(&self, body: String) -> Result<()> {
        let issue_handler = self.octocrab.issues(
            self.context.repository.owner.clone(),
            self.context.repository.name.clone(),

View on GitHub (pinned to 6c226ddcb3)

Solutions

  1. Sanitize the token: remove trailing newlines/whitespace before it reaches the process (printf '%s' "$TOKEN" > file, or tr -d '\r\n')
  2. Re-run with RUST_BACKTRACE=1 and temporarily change map_err to forward the source error (anyhow!("...failed: {e:?}")) to see the real octocrab error
  3. Check octocrab/reqwest version compatibility in Cargo.lock after a dependency bump

Example fix

// before (linera-summary/src/github.rs)
.build()
.map_err(|_| anyhow!("Creating Octocrab instance should not fail!"))?;

// after (forward the cause for diagnosability)
.build()
.map_err(|e| anyhow!("Creating Octocrab instance failed: {e}"))?;
Defensive patterns

Strategy: try-catch

Try / catch

// Keep the source error so failures are diagnosable
let octocrab = match octocrab_builder.build() {
    Ok(client) => client,
    Err(e) => return Err(anyhow::anyhow!("Octocrab init failed: {e}"
        ).context("check GITHUB_TOKEN format and HTTP client config")),
};

Prevention

When it happens

Trigger: Octocrab::builder().personal_token(...).build() failing because the token produces an invalid Authorization header value (e.g. contains a newline), or a custom reqwest/hyper client added to the builder with incompatible TLS settings.

Common situations: A GITHUB_TOKEN copied with embedded whitespace/CR from a CI log; a pinned octocrab version whose builder rejects proxy or TLS options; almost never happens with plain builder usage in the default configuration.

Related errors


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