{"record":{"id":"35826417d14b365d","repo":"linera-io/linera-protocol","slug":"github-token-is-not-set-this-must-be-run-from-wit","errorCode":null,"errorMessage":"GITHUB_TOKEN is not set! This must be run from within CI","messagePattern":"GITHUB_TOKEN is not set! This must be run from within CI","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-summary/src/github.rs","lineNumber":164,"sourceCode":"}\n\n/// A GitHub client bound to a PR context, used to query workflow runs/jobs and post comments.\npub struct Github {\n    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.","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-summary/src/github.rs#L146-L182","documentation":"Thrown by Github::new when the tool runs in CI mode and env::var(\"GITHUB_TOKEN\") returns an Err (variable absent or invalid Unicode). Octocrab, the GitHub API client, requires a personal access token in CI mode, so construction aborts before any API call is made.","triggerScenarios":"Calling Github::new(false, Some(pr)) in a shell/container/CI job where GITHUB_TOKEN was never exported, was unset by a cleanup step, or contains non-UTF8 bytes.","commonSituations":"GitHub Actions job missing the automatic `env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}` mapping; local test harness spawning the process with a scrubbed environment; token name typo such as GH_TOKEN or GITHUB_SECRET_TOKEN.","solutions":["Export the token in the calling environment: export GITHUB_TOKEN=$(gh auth token) locally, or env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} in a workflow","Verify presence before launch: test -n \"$GITHUB_TOKEN\" || { echo 'GITHUB_TOKEN missing'; exit 1; }","If the secret is workflow-scoped, confirm the job has `permissions: pull-requests: write` and the secret is not restricted to other jobs","For local runs, use local mode (is_local=true) which skips the token requirement"],"exampleFix":"# before\n# job yaml with no env block -> Github::new fails in CI mode\n\n# after\n- name: Post PR summary\n  env:\n    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n  run: cargo run -p linera-summary -- --pr ${{ github.event.number }}","handlingStrategy":"validation","validationCode":"// Fail fast with a clear message before Github::new\nif !is_local && std::env::var_os(\"GITHUB_TOKEN\").is_none() {\n    anyhow::bail!(\"GITHUB_TOKEN missing: export it or run with --local\");\n}","typeGuard":null,"tryCatchPattern":"let gh = match Github::new(false, Some(pr)).context(\"building GitHub client\") {\n    Ok(gh) => gh,\n    Err(e) if e.to_string().contains(\"GITHUB_TOKEN\") => {\n        // env problem, not a code bug: surface actionable message and stop\n        return Err(e.context(\"run inside CI or export GITHUB_TOKEN\"));\n    }\n    Err(e) => return Err(e),\n};","preventionTips":["Map secrets.GITHUB_TOKEN into the job env in every workflow step that runs linera-summary","Use `gh auth token` to populate GITHUB_TOKEN for local dry runs","Prefer running the summary tool only from CI, keeping local mode for tests"],"tags":["github","ci","environment-variable","authentication","octocrab","rust"],"backgroundTag":"missing-env-var","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}