From 80fcdff70428bd0c8494d9673bd26cd4d8838cb7 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 24 Feb 2026 21:48:15 -0700 Subject: [PATCH] Fix a panic in can_resolve when the excerpt id is unknown Cherry-pick of #50052 --- crates/multi_buffer/src/multi_buffer.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 95b90ccc297fb0f70c15429b8c3ec097bf4c0927..ac7f3cbe9d0381db1054d359b7dcf5ee0100e403 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -6847,18 +6847,23 @@ impl MultiBufferSnapshot { } fn excerpt_locator_for_id(&self, id: ExcerptId) -> &Locator { + self.try_excerpt_locator_for_id(id) + .unwrap_or_else(|| panic!("invalid excerpt id {id:?}")) + } + + fn try_excerpt_locator_for_id(&self, id: ExcerptId) -> Option<&Locator> { if id == ExcerptId::min() { - Locator::min_ref() + Some(Locator::min_ref()) } else if id == ExcerptId::max() { - Locator::max_ref() + Some(Locator::max_ref()) } else { let (_, _, item) = self.excerpt_ids.find::((), &id, Bias::Left); if let Some(entry) = item && entry.id == id { - return &entry.locator; + return Some(&entry.locator); } - panic!("invalid excerpt id {id:?}") + None } } @@ -6944,7 +6949,7 @@ impl MultiBufferSnapshot { fn excerpt(&self, excerpt_id: ExcerptId) -> Option<&Excerpt> { let excerpt_id = self.latest_excerpt_id(excerpt_id); let mut cursor = self.excerpts.cursor::>(()); - let locator = self.excerpt_locator_for_id(excerpt_id); + let locator = self.try_excerpt_locator_for_id(excerpt_id)?; cursor.seek(&Some(locator), Bias::Left); if let Some(excerpt) = cursor.item() && excerpt.id == excerpt_id