Skip to content

fix: replace strip_suffix(".readonly").unwrap() with unwrap_or#192

Open
Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/strip-suffix-unwrap
Open

fix: replace strip_suffix(".readonly").unwrap() with unwrap_or#192
Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Bortlesboat:fix/strip-suffix-unwrap

Conversation

@Bortlesboat
Copy link
Contributor

Summary

Three call sites used .strip_suffix(".readonly").unwrap() which would panic if a scope URL flagged as is_readonly didn't actually end with ".readonly". While the current data makes this unlikely, using unwrap_or is a defensive improvement that prevents potential panics from inconsistent discovery data.

Changes

  • src/auth_commands.rs (2 locations): scope recommendation logic
  • src/setup_tui.rs (1 location): readonly/superset toggle interdependency

All three are guarded by an is_readonly or ends_with(".readonly") check, so the unwrap is currently safe — but unwrap_or is strictly better since it handles edge cases without panicking.

Test plan

  • CI: cargo test, cargo clippy, cargo fmt

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 enhances the application's robustness by refactoring string manipulation logic to prevent potential panics. It specifically addresses cases where strip_suffix(".readonly").unwrap() could fail if the .readonly suffix was unexpectedly absent, replacing it with a safer unwrap_or approach. This change ensures more resilient handling of scope URLs and improves overall system stability.

Highlights

  • Defensive Programming: Replaced strip_suffix(".readonly").unwrap() with unwrap_or in three locations to prevent potential panics if a scope URL flagged as is_readonly does not actually end with ".readonly".
  • Error Handling Robustness: Enhanced error handling in src/auth_commands.rs and src/setup_tui.rs to gracefully handle unexpected string formats, improving application stability and preventing crashes from inconsistent discovery data.
Changelog
  • .changeset/fix-strip-suffix-unwrap.md
    • Added a new changeset file documenting the fix for the strip_suffix unwrap issue.
  • src/auth_commands.rs
    • Updated two instances of scope recommendation logic to use unwrap_or for safer string manipulation.
    • Improved defensive programming when handling .readonly suffixes in scope URLs.
  • src/setup_tui.rs
    • Modified the readonly/superset toggle interdependency logic to prevent panics during string stripping.
    • Replaced unwrap() with unwrap_or() for robust handling of current_label.
Activity
  • No human activity (comments, reviews) has been recorded on this pull request yet.
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
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 improves the robustness of the application by replacing .unwrap() calls with .unwrap_or() when stripping the .readonly suffix from scope URLs. This is a good defensive change that prevents potential panics from inconsistent data. The changes in src/auth_commands.rs and src/setup_tui.rs are correct and achieve this goal.

I've added one comment in src/auth_commands.rs suggesting a small refactoring to address duplicated code, which would improve maintainability.

Two call sites in auth_commands.rs and setup_tui.rs used
.strip_suffix(".readonly").unwrap(), which panics if a scope URL
flagged as is_readonly doesn't end with ".readonly".

Replace with .unwrap_or() to gracefully fall back to the original
URL rather than crashing on inconsistent discovery data.
@Bortlesboat Bortlesboat force-pushed the fix/strip-suffix-unwrap branch from b891edc to d23ecc9 Compare March 5, 2026 17:34
@changeset-bot
Copy link

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: d23ecc9

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jpoehnelt jpoehnelt added area: discovery cla: yes This human has signed the Contributor License Agreement. complexity: low Small, straightforward change labels Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: discovery cla: yes This human has signed the Contributor License Agreement. complexity: low Small, straightforward change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants