Skip to content

Commit c3340c6

Browse files
ztsalexeyclaudeilblackdragonCopilot
authored
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 <noreply@anthropic.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Illia Polosukhin <ilblackdragon@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 3669a7b commit c3340c6

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/llm/failover.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ impl FailoverProvider {
216216
.cooldown_activated_nanos
217217
.load(Ordering::Relaxed)
218218
})
219-
.expect("providers list is non-empty");
219+
.ok_or_else(|| LlmError::RequestFailed {
220+
provider: "failover".to_string(),
221+
reason: "FailoverProvider requires at least one provider".to_string(),
222+
})?;
220223
tracing::info!(
221224
provider = %self.providers[oldest].model_name(),
222225
"All providers in cooldown, trying oldest-cooled provider"
@@ -266,9 +269,10 @@ impl FailoverProvider {
266269
}
267270
}
268271

269-
// SAFETY: `available` is non-empty (guaranteed above), so at least one
270-
// iteration ran and `last_error` is `Some`.
271-
Err(last_error.expect("available providers list is non-empty"))
272+
Err(last_error.unwrap_or_else(|| LlmError::RequestFailed {
273+
provider: "failover".to_string(),
274+
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(),
275+
}))
272276
}
273277
}
274278

0 commit comments

Comments
 (0)