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
- Sanitize the token: remove trailing newlines/whitespace before it reaches the process (printf '%s' "$TOKEN" > file, or tr -d '\r\n')
- 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
- 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
- Never swallow the octocrab error via map_err(|_| ...); always chain {e}
- Sanitize tokens of trailing newlines before they enter the process env
- Pin octocrab/reqwest versions and re-run CI after dependency upgrades
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
- GITHUB_TOKEN is not set! This must be run from within CI
- GITHUB_PR_NUMBER is not a valid number: {pr_string}
- owner should be different from spender
- invalid block export configuration: {message}
- Expected an `ExecutionError`. Got: {self:#?}
AI-assisted analysis of linera-io/linera-protocol@6c226ddcb3 (2026-08-22).
Data as JSON: /api/errors/5673791c84005b51.
Report an issue: GitHub.