From c3340c60ef043c40bfbc91705f02382695c08363 Mon Sep 17 00:00:00 2001 From: alexthebuildr <116134064+ztsalexey@users.noreply.github.com> Date: Wed, 18 Feb 2026 01:22:18 -0700 Subject: [PATCH] fix: remove .expect() calls in FailoverProvider::try_providers (#156) * fix: remove .expect() calls in FailoverProvider::try_providers (#155) Replace two .expect() calls with proper error propagation to comply with the project no-panic convention. Both were logically unreachable but would panic if invariants were broken by a future refactor. Closes #155 Co-Authored-By: Claude Opus 4.6 * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.6 Co-authored-by: Illia Polosukhin Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/llm/failover.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/llm/failover.rs b/src/llm/failover.rs index ae57dc33..a9cb9ed2 100644 --- a/src/llm/failover.rs +++ b/src/llm/failover.rs @@ -216,7 +216,10 @@ impl FailoverProvider { .cooldown_activated_nanos .load(Ordering::Relaxed) }) - .expect("providers list is non-empty"); + .ok_or_else(|| LlmError::RequestFailed { + provider: "failover".to_string(), + reason: "FailoverProvider requires at least one provider".to_string(), + })?; tracing::info!( provider = %self.providers[oldest].model_name(), "All providers in cooldown, trying oldest-cooled provider" @@ -266,9 +269,10 @@ impl FailoverProvider { } } - // SAFETY: `available` is non-empty (guaranteed above), so at least one - // iteration ran and `last_error` is `Some`. - Err(last_error.expect("available providers list is non-empty")) + Err(last_error.unwrap_or_else(|| LlmError::RequestFailed { + provider: "failover".to_string(), + reason: "Invariant violated in FailoverProvider: providers were exhausted but no last_error was recorded (this branch should be unreachable; possible causes: no provider attempts were made or `available` was unexpectedly empty).".to_string(), + })) } }