Repository navigation
feat: return a typed RateLimitError carrying the retry hint - #65
Merged
Merged
Conversation
ErrRateLimited was a bare sentinel, so a caller running its own backoff could tell that GitHub had throttled the request but not for how long. The client had already parsed Retry-After and X-RateLimit-Reset, capped the result and chosen a fallback, then discarded all of it into an error string the caller would have to re-parse. RateLimitError carries StatusCode, RetryAfter and the response message. It unwraps to ErrRateLimited, so errors.Is keeps working and the rendered message is byte-identical to before; a test pins that string, since callers log and match on it. The retry path now recovers the delay with errors.As instead of threading it through a third return value, so doCreateInstallationToken returns the usual two. RetryAfter is zero when GitHub says to retry immediately or when the reset instant has already passed, which is documented as "retry now" rather than "no hint", since the two are indistinguishable in the value alone.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65 +/- ##
==========================================
+ Coverage 96.94% 97.00% +0.05%
==========================================
Files 4 4
Lines 295 300 +5
==========================================
+ Hits 286 291 +5
Misses 9 9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
ErrRateLimitedis a bare sentinel, so a caller running its own backoff can tell that GitHub throttled the request but not for how long. The client had already readRetry-AfterandX-RateLimit-Reset, capped the result and picked a fallback, then discarded all of it into an error string the caller would have to re-parse from a response it never sees.RateLimitErrorcarries that work forward.Changes
RateLimitError{StatusCode, RetryAfter, Message}, extracted witherrors.AsErrRateLimited, soerrors.Is(err, ErrRateLimited)keeps working; every pre-existing test asserting the sentinel passes untouchederrors.Asrather than threading it through a third return value, sodoCreateInstallationTokenreturns the usual twoRationale
The rendered message is byte-identical to the old
fmt.Errorfoutput, andTest_RateLimitError_MessageFormatpins that string because callers log and match on it.RetryAfteris zero when GitHub says to retry immediately or when the reset instant has already passed; the field documents that as "retry now" rather than "no hint", since the two are indistinguishable from the value alone.Test_RateLimitError_NotReturnedForTerminalFailuresguards the boundary from the other side: a 403 permission failure and a plain 404 must match neithererrors.Asnorerrors.Is.Migration Notes
Purely additive.
errors.Is(err, ErrRateLimited)and the error string are unchanged, so existing callers need no edits.