{"record":{"id":"436898eef2c12186","repo":"666ghj/MiroFish","slug":"github-api-response-could-not-be-read","errorCode":null,"errorMessage":"GitHub API response could not be read","messagePattern":"GitHub API response could not be read","errorType":"exception","errorClass":"FetchError","httpStatus":null,"severity":"error","filePath":"scripts/fetch_star_count.py","lineNumber":109,"sourceCode":"        exc.close()\n        raise _status_error(status) from None\n    except (urllib.error.URLError, TimeoutError, OSError):\n        raise FetchError(\"GitHub API network request failed\") from None\n    except Exception:\n        raise FetchError(\"GitHub API request could not be started\") from None\n\n    try:\n        with response:\n            if response.geturl() != API_URL:\n                raise FetchError(\"GitHub API redirect was refused\")\n            status = response.getcode()\n            if status != 200:\n                raise _status_error(status)\n            payload = _read_response(response)\n    except FetchError:\n        raise\n    except (TimeoutError, OSError):\n        raise FetchError(\"GitHub API response could not be read\") from None\n    except Exception:\n        raise FetchError(\"GitHub API response could not be processed\") from None\n\n    try:\n        document = json.loads(payload)\n    except (UnicodeDecodeError, json.JSONDecodeError, ValueError):\n        raise FetchError(\"GitHub API returned malformed JSON\") from None\n    if not isinstance(document, dict):\n        raise FetchError(\"GitHub API response had an unexpected shape\")\n\n    count = document.get(\"stargazers_count\")\n    if type(count) is not int or count < 0:\n        raise FetchError(\"GitHub API returned an invalid stargazers_count\")\n    return count\n\n\ndef main(argv: list[str] | None = None) -> int:\n    arguments = sys.argv[1:] if argv is None else argv","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/666ghj/MiroFish/blob/b5b53acc57189a4a42e44a23e149dc655c98fe82/scripts/fetch_star_count.py#L91-L127","documentation":"Raised when reading the response body (inside the with response block) raises TimeoutError or OSError — i.e. the connection was established and status received, but the body read failed or exceeded the 20-second timeout. Distinct from error 105: the request itself succeeded; streaming the payload back did not.","triggerScenarios":"Server or middlebox closes the connection mid-body (Connection reset by peer); the read exceeds TIMEOUT_SECONDS=20 on a stalled connection; TLS renegotiation aborting the stream.","commonSituations":"Flaky CI networks where headers arrive but the body stalls; proxies with short idle timeouts that cut slow transfers; GitHub API incidents dropping connections.","solutions":["Retry with backoff — mid-body connection drops are overwhelmingly transient.","If persistent, measure with curl --limit-rate or a raw socket read to identify where the transfer stalls; suspect proxy idle timeouts between the runner and api.github.com.","For chronically slow networks, raise TIMEOUT_SECONDS (it covers both connect and read via client.open)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        count = fetch_star_count(token)\n        break\n    except FetchError as exc:\n        if exc.args[0] != \"GitHub API response could not be read\":\n            raise\n        time.sleep(2 ** attempt)  # mid-body drops are transient\nelse:\n    raise SystemExit(\"response body unreadable after retries\")","preventionTips":["Keep TIMEOUT_SECONDS aligned with the network's worst case (20 s covers connect+read).","Suspect proxy idle timeouts when bodies consistently stall at the same elapsed time.","Retry this class with backoff but cap attempts — persistent read failures indicate a middlebox, not luck."],"tags":["network","timeout","connection-reset","fetch-star-count"],"backgroundTag":null,"analyzedSha":"b5b53acc57189a4a42e44a23e149dc655c98fe82","analyzedAt":"2026-08-14T22:29:33.146Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}