astral-sh/ruff · error
Transformed content out of bounds ({start:?}..{end:?}) for c
Error message
Transformed content out of bounds ({start:?}..{end:?}) for cell at {idx:?} What it means
Panics in Notebook::update_cell_content when slicing the transformed source with a cell's recorded [start, end] offsets goes out of bounds of the new content. As documented on the method, this only happens if cell offsets were not updated (or were updated incorrectly) before rebuilding cell contents.
Source
Thrown at crates/ruff_notebook/src/notebook.rs:313
/// cell offsets need to be rebuilt.
///
/// ## Panics
///
/// Panics if the transformed content is out of bounds for any cell. This
/// can happen only if the cell offsets were not updated before calling
/// this method or the offsets were updated incorrectly.
fn update_cell_content(&mut self, transformed: &str) -> bool {
let mut missing_separator = false;
for (&idx, &[start, end]) in self
.valid_code_cells
.iter()
.zip(self.cell_offsets.array_windows::<2>())
{
let cell_content = transformed
.get(start.to_usize()..end.to_usize())
.unwrap_or_else(|| {
panic!(
"Transformed content out of bounds ({start:?}..{end:?}) for cell at {idx:?}"
);
});
missing_separator |= !cell_content.ends_with(SYNTHETIC_CELL_SEPARATOR);
self.raw.cells[idx as usize].set_source(SourceValue::StringArray(
UniversalNewlineIterator::from(
// We only need to strip the trailing newline which we added
// while concatenating the cell contents.
cell_content.strip_suffix('\n').unwrap_or(cell_content),
)
.map(|line| line.as_full_str().to_string())
.collect::<Vec<_>>(),
));
}
missing_separator
}
View on GitHub (pinned to 26f38c119c)
Solutions
- Recompute cell_offsets before calling update_cell_content
- Return false/propagate an error instead of panicking when offsets do not fit the transformed content
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/ruff_notebook/src/notebook.rs:313 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05).
Data as JSON: /api/errors/74bcee665814d1a5.
Report an issue: GitHub.