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

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.
This commit is contained in:
Andrew Barnes
2026-03-05 18:35:56 -05:00
committed by GitHub
parent ff53538b9f
commit c80eb5274d
3 changed files with 13 additions and 2 deletions
+11
View File
@@ -0,0 +1,11 @@
---
"@anthropic/gws": patch
---
Replace strip_suffix(".readonly").unwrap() with unwrap_or fallback
Two call sites used `.strip_suffix(".readonly").unwrap()` which would
panic if a scope URL marked 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.
+1 -1
View File
@@ -802,7 +802,7 @@ fn run_discovery_scope_picker(
};
let is_recommended = if entry.is_readonly {
let superset = entry.url.strip_suffix(".readonly").unwrap();
let superset = entry.url.strip_suffix(".readonly").unwrap_or(&entry.url);
let superset_is_recommended = filtered_scopes
.iter()
.any(|s| s.url == superset && s.classification != ScopeClassification::Restricted);
+1 -1
View File
@@ -184,7 +184,7 @@ impl PickerState {
// Only deselect the counterpart when we are SELECTING an item
if current_selected {
let counterpart_to_deselect = if current_label.ends_with(".readonly") {
current_label.strip_suffix(".readonly").unwrap().to_string()
current_label.strip_suffix(".readonly").unwrap_or(&current_label).to_string()
} else {
format!("{}.readonly", current_label)
};