fix(gitea): ensure consistent lastErr return for network errors
PR Ready Gate / clear-labels (pull_request) Successful in 2s
CI / test (pull_request) Successful in 17s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 35s
CI / review (gpt-5, security, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 58s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 1m37s
PR Ready Gate / clear-labels (pull_request) Successful in 2s
CI / test (pull_request) Successful in 17s
CI / review (anthropic--claude-4.6-sonnet, sonnet, SONNET_REVIEW_TOKEN) (pull_request) Successful in 35s
CI / review (gpt-5, security, SECURITY_REVIEW.md, SECURITY_REVIEW_TOKEN) (pull_request) Successful in 58s
CI / review (gpt-5, gpt, GPT_REVIEW_TOKEN) (pull_request) Successful in 1m37s
Move lastErr assignment outside the retry condition so that both network errors and HTTP 5xx paths return lastErr consistently. Previously, on the final retry attempt, a network error would return the raw err variable instead of lastErr. While they held the same value in practice, the inconsistency was confusing when reading the code. Now both paths: - Network errors: assign lastErr before checking retry, return lastErr - HTTP 5xx: assign lastErr before checking retry, return lastErr Addresses review finding #3 (MINOR) from sonnet review on PR #69.
This commit is contained in:
+7
-5
@@ -374,19 +374,21 @@ func (c *Client) doGet(ctx context.Context, reqURL string) ([]byte, error) {
|
|||||||
|
|
||||||
resp, err := c.http.Do(req)
|
resp, err := c.http.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Check if this is a temporary/transient network error worth retrying.
|
// Always capture the error for consistent return at loop end.
|
||||||
// We only retry if there are attempts remaining.
|
// This ensures both network errors and HTTP 5xx return lastErr.
|
||||||
|
lastErr = err
|
||||||
|
|
||||||
|
// Only retry temporary network errors when attempts remain.
|
||||||
if attempt < maxAttempts-1 && isTemporaryNetError(err) {
|
if attempt < maxAttempts-1 && isTemporaryNetError(err) {
|
||||||
slog.Warn("temporary network error, will retry",
|
slog.Warn("temporary network error, will retry",
|
||||||
"attempt", attempt+1,
|
"attempt", attempt+1,
|
||||||
"url", redactURL(reqURL),
|
"url", redactURL(reqURL),
|
||||||
"error", err)
|
"error", err)
|
||||||
lastErr = err
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return nil, err
|
// Non-retryable network error or final attempt exhausted.
|
||||||
|
return nil, lastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|||||||
Reference in New Issue
Block a user