on main help sign in
fix(llm): log error when retrying (#781)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commit2437feb0ab546bc8db82f1a9f8e943b8bd7e1908 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateMon 18 Aug 2025, 15:09 (1 year ago) parentff5d689
3 files changed+6−7
internal/llm/provider/anthropic.go+2−3 internal/llm/provider/gemini.go+2−2 internal/llm/provider/openai.go+2−2
internal/llm/provider/anthropic.go+2−3
@@ -291,13 +291,12 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
291291 )
292292 // If there is an error we are going to see if we can retry the call
293293 if err != nil {
294− slog.Error("Anthropic API error", "error", err.Error(), "attempt", attempts, "max_retries", maxRetries)
295294 retry, after, retryErr := a.shouldRetry(attempts, err)
296295 if retryErr != nil {
297296 return nil, retryErr
298297 }
299298 if retry {
300− slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
299+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries, "error", err)
301300 select {
302301 case <-ctx.Done():
303302 return nil, ctx.Err()
@@ -446,7 +445,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
446445 return
447446 }
448447 if retry {
449− slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
448+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries, "error", err)
450449 select {
451450 case <-ctx.Done():
452451 // context cancelled
internal/llm/provider/gemini.go+2−2
@@ -216,7 +216,7 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too
216216 return nil, retryErr
217217 }
218218 if retry {
219− slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
219+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries, "error", err)
220220 select {
221221 case <-ctx.Done():
222222 return nil, ctx.Err()
@@ -327,7 +327,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
327327 return
328328 }
329329 if retry {
330− slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
330+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries, "error", err)
331331 select {
332332 case <-ctx.Done():
333333 if ctx.Err() != nil {
internal/llm/provider/openai.go+2−2
@@ -282,7 +282,7 @@ func (o *openaiClient) send(ctx context.Context, messages []message.Message, too
282282 return nil, retryErr
283283 }
284284 if retry {
285− slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
285+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries, "error", err)
286286 select {
287287 case <-ctx.Done():
288288 return nil, ctx.Err()
@@ -463,7 +463,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
463463 return
464464 }
465465 if retry {
466− slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries)
466+ slog.Warn("Retrying due to rate limit", "attempt", attempts, "max_retries", maxRetries, "error", err)
467467 select {
468468 case <-ctx.Done():
469469 // context cancelled