on main help sign in
fix(llm): log error when retrying (#781)
2437febCarlos Alexandro Becker
internal/llm/provider/anthropic.go+2−3
@@ -291,13 +291,12 @@ func (a *anthropicClient) send(ctx context.Context, messages []message.Message,
291 )
291 )
292 // If there is an error we are going to see if we can retry the call
292 // If there is an error we are going to see if we can retry the call
293 if err != nil {
293 if err != nil {
294− slog.Error("Anthropic API error", "error", err.Error(), "attempt", attempts, "max_retries", maxRetries)
295 retry, after, retryErr := a.shouldRetry(attempts, err)
294 retry, after, retryErr := a.shouldRetry(attempts, err)
296 if retryErr != nil {
295 if retryErr != nil {
297 return nil, retryErr
296 return nil, retryErr
298 }
297 }
299 if retry {
298 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)
301 select {
300 select {
302 case <-ctx.Done():
301 case <-ctx.Done():
303 return nil, ctx.Err()
302 return nil, ctx.Err()
@@ -446,7 +445,7 @@ func (a *anthropicClient) stream(ctx context.Context, messages []message.Message
446 return
445 return
447 }
446 }
448 if retry {
447 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)
450 select {
449 select {
451 case <-ctx.Done():
450 case <-ctx.Done():
452 // context cancelled
451 // context cancelled
internal/llm/provider/gemini.go+2−2
@@ -216,7 +216,7 @@ func (g *geminiClient) send(ctx context.Context, messages []message.Message, too
216 return nil, retryErr
216 return nil, retryErr
217 }
217 }
218 if retry {
218 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)
220 select {
220 select {
221 case <-ctx.Done():
221 case <-ctx.Done():
222 return nil, ctx.Err()
222 return nil, ctx.Err()
@@ -327,7 +327,7 @@ func (g *geminiClient) stream(ctx context.Context, messages []message.Message, t
327 return
327 return
328 }
328 }
329 if retry {
329 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)
331 select {
331 select {
332 case <-ctx.Done():
332 case <-ctx.Done():
333 if ctx.Err() != nil {
333 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
282 return nil, retryErr
282 return nil, retryErr
283 }
283 }
284 if retry {
284 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)
286 select {
286 select {
287 case <-ctx.Done():
287 case <-ctx.Done():
288 return nil, ctx.Err()
288 return nil, ctx.Err()
@@ -463,7 +463,7 @@ func (o *openaiClient) stream(ctx context.Context, messages []message.Message, t
463 return
463 return
464 }
464 }
465 if retry {
465 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)
467 select {
467 select {
468 case <-ctx.Done():
468 case <-ctx.Done():
469 // context cancelled
469 // context cancelled