{"record":{"id":"5673791c84005b51","repo":"linera-io/linera-protocol","slug":"creating-octocrab-instance-should-not-fail","errorCode":null,"errorMessage":"Creating Octocrab instance should not fail!","messagePattern":"Creating Octocrab instance should not fail!","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-summary/src/github.rs","lineNumber":168,"sourceCode":"    octocrab: Octocrab,\n    context: GithubContext,\n    is_local: bool,\n}\n\nimpl Github {\n    /// Builds a client from the environment, in local or CI mode, for the given PR number.\n    pub fn new(is_local: bool, pr_number: Option<u64>) -> Result<Self> {\n        let octocrab_builder = Octocrab::builder();\n        let octocrab =\n            if is_local {\n                octocrab_builder\n            } else {\n                octocrab_builder.personal_token(env::var(\"GITHUB_TOKEN\").map_err(|_| {\n                    anyhow!(\"GITHUB_TOKEN is not set! This must be run from within CI\")\n                })?)\n            }\n            .build()\n            .map_err(|_| anyhow!(\"Creating Octocrab instance should not fail!\"))?;\n\n        Ok(Self {\n            octocrab,\n            context: GithubContext::from_env(is_local, pr_number)?,\n            is_local,\n        })\n    }\n\n    /// Returns the PR context this client is bound to.\n    pub fn context(&self) -> &GithubContext {\n        &self.context\n    }\n\n    /// Updates the tool's existing summary comment on the PR, or creates one if absent.\n    pub async fn upsert_pr_comment(&self, body: String) -> Result<()> {\n        let issue_handler = self.octocrab.issues(\n            self.context.repository.owner.clone(),\n            self.context.repository.name.clone(),","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-summary/src/github.rs#L150-L186","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (linera-summary/src/github.rs)\n.build()\n.map_err(|_| anyhow!(\"Creating Octocrab instance should not fail!\"))?;\n\n// after (forward the cause for diagnosability)\n.build()\n.map_err(|e| anyhow!(\"Creating Octocrab instance failed: {e}\"))?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Keep the source error so failures are diagnosable\nlet octocrab = match octocrab_builder.build() {\n    Ok(client) => client,\n    Err(e) => return Err(anyhow::anyhow!(\"Octocrab init failed: {e}\"\n        ).context(\"check GITHUB_TOKEN format and HTTP client config\")),\n};","preventionTips":["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"],"tags":["github","octocrab","client-initialization","rust"],"backgroundTag":"client-initialization-failed","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}