fix: replace strip_suffix(".readonly").unwrap() with unwrap_or#192
fix: replace strip_suffix(".readonly").unwrap() with unwrap_or#192Bortlesboat wants to merge 1 commit intogoogleworkspace:mainfrom
Conversation
Summary of ChangesHello, 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 Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
b891edc to
d23ecc9
Compare
🦋 Changeset detectedLatest 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 |
Summary
Three call sites used
.strip_suffix(".readonly").unwrap()which would panic if a scope URL flagged asis_readonlydidn't actually end with ".readonly". While the current data makes this unlikely, usingunwrap_oris a defensive improvement that prevents potential panics from inconsistent discovery data.Changes
src/auth_commands.rs(2 locations): scope recommendation logicsrc/setup_tui.rs(1 location): readonly/superset toggle interdependencyAll three are guarded by an
is_readonlyorends_with(".readonly")check, so the unwrap is currently safe — butunwrap_oris strictly better since it handles edge cases without panicking.Test plan
cargo test,cargo clippy,cargo fmt