{"record":{"id":"203dfbf9a0335609","repo":"unslothai/unsloth","slug":"gh-token-or-github-token-not-set-in-environment","errorCode":null,"errorMessage":"GH_TOKEN or GITHUB_TOKEN not set in environment","messagePattern":"GH_TOKEN or GITHUB_TOKEN not set in environment","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/gh_client.py","lineNumber":71,"sourceCode":"\nclass GitHubClient:\n    def __init__(\n        self,\n        min_remaining_graphql: int = 100,\n        min_remaining_rest: int = 100,\n        token: str | None = None,\n        token_source: str | None = None,\n    ):\n        if token:\n            self._token_source = token_source or \"explicit token argument (recipe-level field)\"\n        elif os.environ.get(\"GH_TOKEN\"):\n            self._token_source = \"GH_TOKEN environment variable\"\n            token = os.environ[\"GH_TOKEN\"]\n        elif os.environ.get(\"GITHUB_TOKEN\"):\n            self._token_source = \"GITHUB_TOKEN environment variable\"\n            token = os.environ[\"GITHUB_TOKEN\"]\n        else:\n            raise RuntimeError(\"GH_TOKEN or GITHUB_TOKEN not set in environment\")\n        self.session = requests.Session()\n        self.session.headers.update({**BASE_HEADERS, \"Authorization\": f\"Bearer {token}\"})\n        self.min_remaining_graphql = min_remaining_graphql\n        self.min_remaining_rest = min_remaining_rest\n        self.graphql_remaining: Optional[int] = None\n        self.graphql_reset: Optional[int] = None\n        self.rest_remaining: Optional[int] = None\n        self.rest_reset: Optional[int] = None\n        self.calls_graphql = 0\n        self.calls_rest = 0\n        self.retry_count = 0\n\n    def _sleep_until(\n        self,\n        reset_ts: int,\n        buffer_s: int = 10,\n    ) -> None:\n        now = int(time.time())","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/plugins/data-designer-github-repo-seed/src/data_designer_github_repo_seed/scraper_impl/gh_client.py#L53-L89","documentation":"RuntimeError raised in the constructor of the GitHub client (gh_client) when no token is available: no explicit token argument, no GH_TOKEN, no GITHUB_TOKEN. Unlike scraper.py's ValueError (error 969) this is the low-level client failing at instantiation — it cannot build an authenticated session without a bearer token, and anonymous GraphQL access is not possible.","triggerScenarios":"Constructing the client class directly (e.g. GitHubClient()) without arguments in an environment lacking GH_TOKEN/GITHUB_TOKEN, or the scraper path reaching client construction with token resolution having returned nothing.","commonSituations":"Unit tests instantiating the client without mocking env vars; scripts that import the internal scraper_impl module and build the client themselves; cron/systemd services missing Environment=GH_TOKEN=... definitions.","solutions":["Pass the token explicitly to the constructor (token=..., token_source=...) when driving the client directly.","Or export GH_TOKEN / GITHUB_TOKEN before the process starts.","In tests, set a dummy env var or inject a stub session rather than relying on real credentials."],"exampleFix":"# before\nclient = GitHubClient()  # RuntimeError: GH_TOKEN or GITHUB_TOKEN not set\n\n# after\nclient = GitHubClient(token=os.environ[\"MY_TOKEN\"], token_source=\"MY_TOKEN env\")","handlingStrategy":"validation","validationCode":"import os\n\ndef can_construct_client(explicit_token: str | None = None) -> bool:\n    return bool(explicit_token or os.environ.get(\"GH_TOKEN\") or os.environ.get(\"GITHUB_TOKEN\"))\n\nassert can_construct_client(), \"set GH_TOKEN before creating the client\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using scraper_impl directly, always pass token explicitly rather than relying on env.","In tests, monkeypatch GH_TOKEN to a dummy value before instantiating the client."],"tags":["github","authentication","environment","runtime-error"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}