From aa9dacad285ef1010908edc8b75748e90ed5146e Mon Sep 17 00:00:00 2001 From: Smit Barmase Date: Wed, 18 Jun 2025 22:16:07 +0530 Subject: [PATCH] editor: Log error instead of panic on index out of bounds for line layouts (#32953) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #30191 `line_ix` should never exceed the bounds of `line_layouts`, but a panic happens on out-of-bounds for this, which seems weird. I couldn’t reproduce this panic at all. Since this is for displaying inline blame, we now log an error if this occurs instead of panicking. Release Notes: - N/A --- crates/editor/src/element.rs | 49 ++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 4d3e571cce..429b1a6739 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -8506,26 +8506,37 @@ impl Element for EditorElement { ); let line_ix = display_row.minus(start_row) as usize; - let row_info = &row_infos[line_ix]; - let line_layout = &line_layouts[line_ix]; - let crease_trailer_layout = crease_trailers[line_ix].as_ref(); - - if let Some(layout) = self.layout_inline_blame( - display_row, - row_info, - line_layout, - crease_trailer_layout, - em_width, - content_origin, - scroll_pixel_position, - line_height, - &text_hitbox, - window, - cx, + if let (Some(row_info), Some(line_layout), Some(crease_trailer)) = ( + row_infos.get(line_ix), + line_layouts.get(line_ix), + crease_trailers.get(line_ix), ) { - inline_blame_layout = Some(layout); - // Blame overrides inline diagnostics - inline_diagnostics.remove(&display_row); + let crease_trailer_layout = crease_trailer.as_ref(); + if let Some(layout) = self.layout_inline_blame( + display_row, + row_info, + line_layout, + crease_trailer_layout, + em_width, + content_origin, + scroll_pixel_position, + line_height, + &text_hitbox, + window, + cx, + ) { + inline_blame_layout = Some(layout); + // Blame overrides inline diagnostics + inline_diagnostics.remove(&display_row); + } + } else { + log::error!( + "bug: line_ix {} is out of bounds - row_infos.len(): {}, line_layouts.len(): {}, crease_trailers.len(): {}", + line_ix, + row_infos.len(), + line_layouts.len(), + crease_trailers.len(), + ); } } }