Skip to content

fix: remove .expect() calls in FailoverProvider::try_providers#156

Merged
ilblackdragon merged 3 commits intonearai:mainfrom
ztsalexey:fix/failover-remove-expect
Feb 18, 2026
Merged

fix: remove .expect() calls in FailoverProvider::try_providers#156
ilblackdragon merged 3 commits intonearai:mainfrom
ztsalexey:fix/failover-remove-expect

Conversation

@ztsalexey
Copy link
Copy Markdown
Contributor

Summary

  • Replace .expect("providers list is non-empty") with .ok_or_else()? error propagation
  • Replace .expect("available providers list is non-empty") with .unwrap_or_else() fallback error

Both were logically unreachable but violated the project no-panic convention.

Closes #155

Test plan

  • All 17 existing failover tests pass: cargo test --lib llm::failover
  • No behavioral change — both paths were unreachable; only the panic-on-invariant-violation behavior changes to error propagation

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 18, 2026 00:00
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ztsalexey, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors error handling within the FailoverProvider to eliminate potential panics from .expect() calls. By replacing these with more robust error propagation and fallback mechanisms, the codebase now aligns better with a no-panic convention, enhancing stability and predictability without altering the intended logic or behavior of the failover system.

Highlights

  • Panic Prevention: Replaced .expect() calls with explicit error propagation (.ok_or_else()?) and fallback (.unwrap_or_else()) to adhere to the project's no-panic convention.
  • Error Handling Improvement: Introduced LlmError::RequestFailed with specific reasons for cases where provider lists are unexpectedly empty or all providers fail, improving error clarity.
  • Behavioral Consistency: Confirmed that these changes introduce no behavioral differences, as the original .expect() paths were logically unreachable.
Changelog
  • src/llm/failover.rs
    • Replaced .expect("providers list is non-empty") with an ok_or_else call that returns LlmError::RequestFailed if no providers are available.
    • Replaced .expect("available providers list is non-empty") with an unwrap_or_else call that returns LlmError::RequestFailed if all providers fail.
Activity
  • All 17 existing failover tests passed, confirming no regressions.
  • No behavioral changes were introduced, as the modified code paths were previously unreachable.
  • The pull request was generated using Claude Code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes two .expect() calls from the FailoverProvider::try_providers method to comply with the project convention of never using .unwrap() or .expect() in production code. Both calls were logically unreachable due to constructor invariants, but could have caused panics if future refactoring violated those invariants.

Changes:

  • Replaced .expect("providers list is non-empty") with .ok_or_else()? for proper error propagation when selecting the oldest-cooled provider
  • Replaced .expect("available providers list is non-empty") with .unwrap_or_else() to provide a fallback error when all providers fail

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly replaces .expect() calls with non-panicking error handling, which improves the robustness of the FailoverProvider and aligns with a no-panic policy. The changes are well-reasoned and improve the code quality. I have one minor suggestion to improve the clarity of an error message in a theoretically unreachable code path, which could aid debugging if a bug ever makes that path reachable.

Comment thread src/llm/failover.rs Outdated
…i#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 nearai#155

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ztsalexey ztsalexey force-pushed the fix/failover-remove-expect branch from 84e0f81 to 5d805b4 Compare February 18, 2026 00:13
Copilot AI review requested due to automatic review settings February 18, 2026 06:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/llm/failover.rs Outdated
Comment thread src/llm/failover.rs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 18, 2026 08:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ilblackdragon ilblackdragon merged commit c3340c6 into nearai:main Feb 18, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 18, 2026
jaswinder6991 pushed a commit to jaswinder6991/ironclaw that referenced this pull request Feb 26, 2026
…i#156)

* fix: remove .expect() calls in FailoverProvider::try_providers (nearai#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 nearai#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>
bkutasi pushed a commit to bkutasi/ironclaw that referenced this pull request Mar 28, 2026
…i#156)

* fix: remove .expect() calls in FailoverProvider::try_providers (nearai#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 nearai#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: remove .expect() calls in FailoverProvider::try_providers

3 participants