Skip to content

Commit dcfb3c7

Browse files
committed
modelerrors: unexport IsRetryableStatusCode and ExtractHTTPStatusCode
Both are only used within the package. Rename to isRetryableStatusCode and extractHTTPStatusCode to reduce the public API surface. Assisted-By: docker-agent
1 parent f699806 commit dcfb3c7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

pkg/modelerrors/modelerrors.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ func IsContextOverflowError(err error) bool {
161161
// statusCodeRegex matches HTTP status codes in error messages (e.g., "429", "500", ": 429 ")
162162
var statusCodeRegex = regexp.MustCompile(`\b([45]\d{2})\b`)
163163

164-
// ExtractHTTPStatusCode attempts to extract an HTTP status code from the error
164+
// extractHTTPStatusCode attempts to extract an HTTP status code from the error
165165
// using regex parsing of the error message. This is a fallback for providers
166166
// whose errors are not yet wrapped in *StatusError (the preferred path).
167167
//
168168
// The regex matches 4xx/5xx codes at word boundaries
169169
// (e.g., "429 Too Many Requests", "500 Internal Server Error").
170170
// Returns 0 if no status code found.
171-
func ExtractHTTPStatusCode(err error) int {
171+
func extractHTTPStatusCode(err error) int {
172172
if err == nil {
173173
return 0
174174
}
@@ -191,7 +191,7 @@ func ExtractHTTPStatusCode(err error) int {
191191
return 0
192192
}
193193

194-
// IsRetryableStatusCode determines if an HTTP status code is retryable.
194+
// isRetryableStatusCode determines if an HTTP status code is retryable.
195195
// Retryable means we should retry the SAME model with exponential backoff.
196196
//
197197
// Retryable status codes:
@@ -202,7 +202,7 @@ func ExtractHTTPStatusCode(err error) int {
202202
// Non-retryable status codes (skip to next model immediately):
203203
// - 429 (rate limit) - provider is explicitly telling us to back off
204204
// - 4xx client errors (400, 401, 403, 404) - won't get better with retry
205-
func IsRetryableStatusCode(statusCode int) bool {
205+
func isRetryableStatusCode(statusCode int) bool {
206206
switch statusCode {
207207
case 500, 502, 503, 504: // Server errors
208208
return true
@@ -219,7 +219,7 @@ func IsRetryableStatusCode(statusCode int) bool {
219219

220220
// retryablePatterns contains error message substrings that indicate a
221221
// transient/retryable failure. Numeric status codes (500, 502, etc.) are
222-
// handled separately by ExtractHTTPStatusCode + IsRetryableStatusCode.
222+
// handled separately by extractHTTPStatusCode + isRetryableStatusCode.
223223
var retryablePatterns = []string{
224224
"timeout", // Generic timeout
225225
"connection reset", // Connection reset
@@ -241,7 +241,7 @@ var retryablePatterns = []string{
241241

242242
// nonRetryablePatterns contains error message substrings that indicate a
243243
// permanent/non-retryable failure. Numeric status codes (429, 401, etc.) are
244-
// handled separately by ExtractHTTPStatusCode.
244+
// handled separately by extractHTTPStatusCode.
245245
var nonRetryablePatterns = []string{
246246
"rate limit", // Rate limit message
247247
"too many requests", // Rate limit message
@@ -292,8 +292,8 @@ func isRetryableModelError(err error) bool {
292292
}
293293

294294
// First, try to extract HTTP status code from known SDK error types
295-
if statusCode := ExtractHTTPStatusCode(err); statusCode != 0 {
296-
retryable := IsRetryableStatusCode(statusCode)
295+
if statusCode := extractHTTPStatusCode(err); statusCode != 0 {
296+
retryable := isRetryableStatusCode(statusCode)
297297
slog.Debug("Classified error by status code",
298298
"status_code", statusCode,
299299
"retryable", retryable)
@@ -387,17 +387,17 @@ func ClassifyModelError(err error) (retryable, rateLimited bool, retryAfter time
387387
if statusErr.StatusCode == http.StatusTooManyRequests {
388388
return false, true, statusErr.RetryAfter
389389
}
390-
return IsRetryableStatusCode(statusErr.StatusCode), false, 0
390+
return isRetryableStatusCode(statusErr.StatusCode), false, 0
391391
}
392392

393393
// Fallback: providers that don't yet wrap (e.g. Bedrock), or non-provider
394394
// errors (network, pattern matching).
395-
statusCode := ExtractHTTPStatusCode(err)
395+
statusCode := extractHTTPStatusCode(err)
396396
if statusCode == http.StatusTooManyRequests {
397397
return false, true, 0 // No Retry-After without StatusError
398398
}
399399
if statusCode != 0 {
400-
return IsRetryableStatusCode(statusCode), false, 0
400+
return isRetryableStatusCode(statusCode), false, 0
401401
}
402402
return isRetryableModelError(err), false, 0
403403
}

pkg/modelerrors/modelerrors_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestExtractHTTPStatusCode(t *testing.T) {
9494
for _, tt := range tests {
9595
t.Run(tt.name, func(t *testing.T) {
9696
t.Parallel()
97-
assert.Equal(t, tt.expected, ExtractHTTPStatusCode(tt.err), "ExtractHTTPStatusCode(%v)", tt.err)
97+
assert.Equal(t, tt.expected, extractHTTPStatusCode(tt.err), "extractHTTPStatusCode(%v)", tt.err)
9898
})
9999
}
100100
}
@@ -118,7 +118,7 @@ func TestIsRetryableStatusCode(t *testing.T) {
118118
for _, tt := range tests {
119119
t.Run(fmt.Sprintf("status_%d", tt.statusCode), func(t *testing.T) {
120120
t.Parallel()
121-
assert.Equal(t, tt.expected, IsRetryableStatusCode(tt.statusCode), "IsRetryableStatusCode(%d)", tt.statusCode)
121+
assert.Equal(t, tt.expected, isRetryableStatusCode(tt.statusCode), "isRetryableStatusCode(%d)", tt.statusCode)
122122
})
123123
}
124124
}

0 commit comments

Comments
 (0)