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 <[email protected]>

* Apply suggestions from code review

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 <[email protected]>
Co-authored-by: Illia Polosukhin <[email protected]>
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
alexthebuildr
2026-02-18 08:22:18 +00:00
committed by GitHub
co-authored by Claude Opus 4.6 Illia Polosukhin Copilot
parent 3669a7b1cd
commit c3340c60ef
+8 -4
View File
@@ -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(),
}))
}
}