{"record":{"id":"d946b7e58b1cebf7","repo":"linera-io/linera-protocol","slug":"github-pr-number-is-not-a-valid-number-pr-string","errorCode":null,"errorMessage":"GITHUB_PR_NUMBER is not a valid number: {pr_string}","messagePattern":"GITHUB_PR_NUMBER is not a valid number: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"linera-summary/src/github.rs","lineNumber":134,"sourceCode":"                pr_number.ok_or_else(|| anyhow!(\"pr_number is None\"))?,\n            )\n        } else {\n            let pr_string = env_pr_number.map_err(|_| {\n                anyhow!(\"GITHUB_PR_NUMBER is not set! This must be run from within CI\")\n            })?;\n            (\n                env_pr_commit_hash.map_err(|_| {\n                    anyhow!(\"GITHUB_PR_COMMIT_HASH is not set! This must be run from within CI\")\n                })?,\n                env_pr_branch.map_err(|_| {\n                    anyhow!(\"GITHUB_PR_BRANCH is not set! This must be run from within CI\")\n                })?,\n                env_base_branch.map_err(|_| {\n                    anyhow!(\"GITHUB_BASE_BRANCH is not set! This must be run from within CI\")\n                })?,\n                pr_string\n                    .parse()\n                    .map_err(|_| anyhow!(\"GITHUB_PR_NUMBER is not a valid number: {pr_string}\"))?,\n            )\n        };\n\n        Ok(Self {\n            repository: GithubRepository::from_env(is_local)?,\n            pr_commit_hash,\n            pr_branch,\n            base_branch,\n            pr_number,\n        })\n    }\n}\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,","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-summary/src/github.rs#L116-L152","documentation":"Thrown by GithubContext::from_env when linera-summary runs in CI mode (is_local=false). The tool reads the GITHUB_PR_NUMBER environment variable and parses it with str::parse::<u64>(); the parse itself only fails when the variable exists but its value is not a bare decimal number. The message interpolates the offending value, so the raw string appears in the error.","triggerScenarios":"Running the linera-summary binary outside GitHub Actions CI but with GITHUB_PR_NUMBER set to something non-numeric (e.g. \"true\", \"refs/pull/123/merge\", an empty string, or a value with whitespace/newline); in CI, exporting the PR from the wrong context expression such as github.ref instead of github.event.number.","commonSituations":"Manually replaying a CI run locally and copying GitHub payload JSON where number fields arrive as strings with quotes or CR/LF; workflow templates that pass \"${{ github.head_ref }}\" by mistake; a step that does `echo GITHUB_PR_NUMBER=123 #comment` on Windows (trailing \\r).","solutions":["Check the exact value printed in the message; strip quotes, whitespace and CR/LF: GITHUB_PR_NUMBER=$(echo \"$GITHUB_PR_NUMBER\" | tr -d '[:space:]')","In GitHub Actions, set it from the numeric event field: env: GITHUB_PR_NUMBER: ${{ github.event.number }}","If running locally, invoke the tool in local mode (is_local=true / --local) so it derives context from git instead of env vars, passing the PR number explicitly","Never assign a git ref like refs/pull/N/merge; use only the bare integer N"],"exampleFix":"# before (workflow yaml)\nenv:\n  GITHUB_PR_NUMBER: ${{ github.ref }}   # \"refs/pull/123/merge\" -> parse fails\n\n# after\nenv:\n  GITHUB_PR_NUMBER: ${{ github.event.number }}","handlingStrategy":"validation","validationCode":"// Rust: validate before constructing the Github client\nfn pr_number_from_env() -> anyhow::Result<u64> {\n    let raw = std::env::var(\"GITHUB_PR_NUMBER\")\n        .map_err(|_| anyhow::anyhow!(\"GITHUB_PR_NUMBER is not set\"))?;\n    let trimmed = raw.trim();\n    trimmed.parse::<u64>().map_err(|_| {\n        anyhow::anyhow!(\"GITHUB_PR_NUMBER={raw:?} is not a PR number\")\n    })\n}","typeGuard":null,"tryCatchPattern":"match Github::new(false, None) {\n    Ok(gh) => gh,\n    Err(e) if e.to_string().contains(\"GITHUB_PR_NUMBER\") => {\n        eprintln!(\"CI env incomplete: {e}\"); return Ok(());\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["In workflows, always derive GITHUB_PR_NUMBER from ${{ github.event.number }}","Trim whitespace and CR in wrapper scripts before launching the binary","Add a startup assert that logs all required GITHUB_* variables when CI mode is on"],"tags":["github","ci","environment-variable","parsing","rust"],"backgroundTag":"invalid-environment-variable","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}