editor: Log error instead of panic on index out of bounds for line layouts (#32953)

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
This commit is contained in:
Smit Barmase 2025-06-18 22:16:07 +05:30 committed by GitHub
parent 48491fa487
commit aa9dacad28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8506,10 +8506,12 @@ impl Element for EditorElement {
); );
let line_ix = display_row.minus(start_row) as usize; let line_ix = display_row.minus(start_row) as usize;
let row_info = &row_infos[line_ix]; if let (Some(row_info), Some(line_layout), Some(crease_trailer)) = (
let line_layout = &line_layouts[line_ix]; row_infos.get(line_ix),
let crease_trailer_layout = crease_trailers[line_ix].as_ref(); line_layouts.get(line_ix),
crease_trailers.get(line_ix),
) {
let crease_trailer_layout = crease_trailer.as_ref();
if let Some(layout) = self.layout_inline_blame( if let Some(layout) = self.layout_inline_blame(
display_row, display_row,
row_info, row_info,
@ -8527,6 +8529,15 @@ impl Element for EditorElement {
// Blame overrides inline diagnostics // Blame overrides inline diagnostics
inline_diagnostics.remove(&display_row); 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(),
);
}
} }
} }