From 8e98d7172b4076b36631ba6ceccbfa7b2bfb0ba1 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Wed, 4 Mar 2026 11:01:34 -0500 Subject: [PATCH] Remove expect() from generate_agent_branch_name Return Option instead of panicking, and handle the None case at the call site using the existing error-reporting pattern. --- crates/agent_ui/src/agent_panel.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/agent_ui/src/agent_panel.rs b/crates/agent_ui/src/agent_panel.rs index 15704c0f452d91b752bfbfc502bec1baa2658bb9..5c65192288b88254ec696b9217de919ab71ed888 100644 --- a/crates/agent_ui/src/agent_panel.rs +++ b/crates/agent_ui/src/agent_panel.rs @@ -2041,10 +2041,9 @@ impl AgentPanel { } } - fn generate_agent_branch_name() -> String { + fn generate_agent_branch_name() -> Option { let mut rng = rand::rng(); crate::branch_names::generate_branch_name(&[], &mut rng) - .expect("should always succeed with no disallowed names") } /// Partitions the project's visible worktrees into git-backed repositories @@ -2246,7 +2245,17 @@ impl AgentPanel { self.worktree_creation_status = Some(WorktreeCreationStatus::Creating); cx.notify(); - let branch_name = Self::generate_agent_branch_name(); + let branch_name = match Self::generate_agent_branch_name() { + Some(name) => name, + None => { + self.set_worktree_creation_error( + "Failed to generate a branch name".into(), + window, + cx, + ); + return; + } + }; let (git_repos, non_git_paths) = self.classify_worktrees(cx);