From 8b572596698c777af81d2b624c8d682c730f330b Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 26 Sep 2024 01:31:17 -0600 Subject: [PATCH] Avoid unwrap in file finder (#18374) Release Notes: - Fixed a (rare) panic in file finder --------- Co-authored-by: Kirill Bulatov --- crates/file_finder/src/file_finder.rs | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index 50a14b62dbb4d1..6fe9f68c6975a8 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -386,7 +386,7 @@ fn matching_history_items<'a>( .chars(), ), }; - candidates_paths.insert(Arc::clone(&found_path.project.path), found_path); + candidates_paths.insert(&found_path.project, found_path); Some((found_path.project.worktree_id, candidate)) }) .fold( @@ -411,17 +411,21 @@ fn matching_history_items<'a>( max_results, ) .into_iter() - .map(|path_match| { - let (_, found_path) = candidates_paths - .remove_entry(&path_match.path) - .expect("candidate info not found"); - ( - Arc::clone(&path_match.path), - Match::History { - path: found_path.clone(), - panel_match: Some(ProjectPanelOrdMatch(path_match)), - }, - ) + .filter_map(|path_match| { + candidates_paths + .remove_entry(&ProjectPath { + worktree_id: WorktreeId::from_usize(path_match.worktree_id), + path: Arc::clone(&path_match.path), + }) + .map(|(_, found_path)| { + ( + Arc::clone(&path_match.path), + Match::History { + path: found_path.clone(), + panel_match: Some(ProjectPanelOrdMatch(path_match)), + }, + ) + }) }), ); }