{"record":{"id":"01ae35def7465c4b","repo":"666ghj/MiroFish","slug":"github-graphql-request-failed-exit-completed-ret","errorCode":null,"errorMessage":"GitHub GraphQL request failed (exit {completed.returncode})","messagePattern":"GitHub GraphQL request failed \\(exit (.+?)\\)","errorType":"exception","errorClass":"StarHistoryError","httpStatus":null,"severity":"error","filePath":"scripts/star_history.py","lineNumber":236,"sourceCode":"        arguments = [\n            \"gh\",\n            \"api\",\n            \"graphql\",\n            \"-f\",\n            f\"query={GRAPHQL_QUERY}\",\n            \"-f\",\n            f\"owner={REPOSITORY_OWNER}\",\n            \"-f\",\n            f\"name={REPOSITORY_NAME}\",\n        ]\n        if after is not None:\n            if not after or \"\\n\" in after or \"\\r\" in after:\n                raise StarHistoryError(\"GitHub returned an invalid pagination cursor\")\n            arguments.extend((\"-f\", f\"after={after}\"))\n\n        completed = self._runner.run(arguments)\n        if completed.returncode != 0:\n            raise StarHistoryError(\n                f\"GitHub GraphQL request failed (exit {completed.returncode})\"\n            )\n        try:\n            payload = json.loads(completed.stdout)\n        except json.JSONDecodeError as exc:\n            raise StarHistoryError(\"GitHub GraphQL returned malformed JSON\") from exc\n\n        if not isinstance(payload, dict) or payload.get(\"errors\"):\n            raise StarHistoryError(\"GitHub GraphQL rejected the stargazer request\")\n        try:\n            data = payload[\"data\"]\n            repository = data[\"repository\"]\n            stargazers = repository[\"stargazers\"]\n            rate_limit = data[\"rateLimit\"]\n            raw_edges = stargazers[\"edges\"]\n            page_info = stargazers[\"pageInfo\"]\n        except (KeyError, TypeError) as exc:\n            raise StarHistoryError(\"GitHub GraphQL response had an unexpected shape\") from exc","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/scripts/star_history.py#L218-L254","documentation":"Raised when the `gh api graphql` subprocess completes with a non-zero exit code. The message interpolates the exit code (e.g. exit 1 for gh-side errors, exit 4 for missing auth in some gh versions, exit 8 for GraphQL HTTP errors). This is the generic 'gh itself reported failure' bucket before any stdout parsing happens.","triggerScenarios":"gh not authenticated (no gh auth login / GH_TOKEN) — gh exits non-zero with 'gh auth login required'; invalid or expired token; gh api HTTP errors against api.github.com; network failure inside gh; GraphQL query field errors that gh surfaces as exit != 0.","commonSituations":"Running backfill on a new machine without gh auth; GH_TOKEN expired or revoked; GitHub API rate limit exhausted (gh exits non-zero on HTTP 403); gh version too old for the pinned GraphQL query shape.","solutions":["Reproduce manually to see gh's stderr: gh api graphql -f query='<the query>' -f owner=666ghj -f name=MiroFish — the real reason is always in stderr.","Authenticate: gh auth login or export GH_TOKEN=<token> with repo read scope.","Check rate limits: gh api rate_limit; backfill pages 100 stargazers at a time, so large repos can exhaust points — wait for reset or reduce PAGE_SIZE.","Upgrade gh if the manual run shows GraphQL field errors (rateLimit/stargazers schema changed): brew upgrade gh."],"exampleFix":"# before: error hides gh's stderr\ncompleted = self._runner.run(arguments)\nif completed.returncode != 0:\n    raise StarHistoryError(\n        f\"GitHub GraphQL request failed (exit {completed.returncode})\"\n    )\n\n# after: surface a bounded, redacted stderr snippet\nif completed.returncode != 0:\n    detail = completed.stderr.strip().splitlines()[:1]\n    raise StarHistoryError(\n        f\"GitHub GraphQL request failed (exit {completed.returncode}): \"\n        f\"{detail[0][:200] if detail else 'no stderr'}\"\n    )","handlingStrategy":"try-catch","validationCode":"import shutil, subprocess\n\n# preflight: gh exists and is authenticated non-interactively\nif shutil.which(\"gh\") is None:\n    raise SystemExit(\"gh not installed\")\nprobe = subprocess.run(\n    [\"gh\", \"auth\", \"status\"], capture_output=True, text=True, timeout=15\n)\nif probe.returncode != 0:\n    raise SystemExit(f\"gh not authenticated: {probe.stderr.strip()[:200]}\")","typeGuard":null,"tryCatchPattern":"try:\n    page = gateway.fetch_stargazer_page(after)\nexcept StarHistoryError as exc:\n    if \"GitHub GraphQL request failed (exit\" in str(exc):\n        # exit code is in the message; the actionable detail is in gh's stderr,\n        # so reproduce the gh command manually to read it\n        raise SystemExit(f\"gh failed: {exc}. Run `gh auth status` and the gh \"\n                         \"api graphql command by hand for details.\")\n    raise","preventionTips":["Always run `gh auth status` as a preflight before backfill.","Patch the raise to include a bounded slice of completed.stderr — the exit code alone is rarely actionable.","Track the exit code: exit 1 usually means auth/query error, HTTP-level failures can map to gh's documented exit codes."],"tags":["github-cli","subprocess","exit-code","authentication","star-history"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}