fix(selfupdate): report a rate-limited 403 as rate limiting, not a private repo - #126
Open
gustavobertoi wants to merge 1 commit into
Open
fix(selfupdate): report a rate-limited 403 as rate limiting, not a private repo#126gustavobertoi wants to merge 1 commit into
gustavobertoi wants to merge 1 commit into
Conversation
…ivate repo
GitHub answers an exhausted API quota with a plain 403 Forbidden, which is
indistinguishable from a permissions failure unless you read the response
headers. Both `self update` and install.sh assumed the permissions case for
every 403 and told the user to "set GITHUB_TOKEN if the repo is private" — so a
user on a PUBLIC repo who had merely used up the anonymous 60-requests/hour
quota went hunting for a permissions problem that did not exist, while the real
cause (and the fact that it clears itself in minutes) stayed hidden.
The distinguishing signal is X-RateLimit-Remaining: 0, plus Retry-After for
secondary limits. apiError now separates four cases:
rate limited -> names the limit that was hit, says plainly that it is NOT a
permissions problem, gives the reset countdown, and still
offers GITHUB_TOKEN as the fix (it raises the cap to 5000/h)
401 -> the token is set but was rejected
404 -> keeps the private-repo hint, which is where it belongs
other -> the bare status
Before:
Github API https://api.github.com/... returned 403 Forbidden (set GITHUB_TOKEN
if the repo is private).
After:
GitHub API rate limit exceeded (60 requests/hour), resets in 10m0s.
This is not a permissions problem — the repository is reachable, you have
simply used up the anonymous quota for your IP.
Set GITHUB_TOKEN (or GH_TOKEN) to raise the limit to 5000 requests/hour: <url>
Applied to both the API path (selfupdate.go) and the asset-download path
(update.go), since the reported failure hit the asset download first.
install.sh cannot read the headers — its api() helper uses `curl -f`, which
discards the error body — so it probes /rate_limit (which does not count against
the quota) and appends the same clarification when the quota is spent.
The reset countdown is omitted rather than rendered when the stamp is in the
past or unparseable, so it can never print "resets in -3m0s".
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The report
The repository is public. The actual cause was the anonymous GitHub API
quota (60 requests/hour per IP) being spent:
GitHub answers an exhausted quota with a plain
403 Forbidden, which isindistinguishable from a permissions failure unless you read the headers. Our
message assumed the permissions case for every 403, so it described a problem
that did not exist and hid the one that did — including that it clears itself in
minutes.
The fix
apiErrornow separates four cases onX-RateLimit-Remaining: 0(plusRetry-After, which is how secondary limits are signalled):GITHUB_TOKEN(it raises the cap to 5000/h)After:
Applied to both the API path (
selfupdate.go) and the asset-download path(
update.go) — the reported failure hit the asset download first, and that pathhad its own, even barer, message.
install.shcannot read the headers, because itsapi()helper usescurl -fwhich discards the error body. It instead probes
/rate_limit(which does notcount against the quota) and appends the same clarification.
Notes
the past or unparseable, so it can never print
resets in -3m0s.failure —
TestForbiddenWithQuotaLeftIsNotRateLimitpins that.🤖 Generated with Claude Code