zed-industries/zed · error

added 1

Error message

added 1

What it means

An arithmetic invariant in the cursor position formatter: after computing the 0-based column (buffer chars since line start), it converts to a 1-based human position via a checked add whose expect message is 'added 1'. It can only fire if the column value is already at u32::MAX — unreachable for real buffer contents — so this panic effectively signals integer overflow in the position math rather than any plausible editor state.

Source

Thrown at crates/go_to_line/src/cursor_position.rs:63

        let (line, character) =
            if let Some((buffer_snapshot, point)) = snapshot.point_to_buffer_point(selection_end) {
                let line_start = Point::new(point.row, 0);

                let chars_to_last_position = buffer_snapshot
                    .text_summary_for_range::<text::TextSummary, _>(line_start..point)
                    .chars as u32;
                (line_start.row, chars_to_last_position)
            } else {
                let line_start = Point::new(selection_end.row, 0);

                let chars_to_last_position = snapshot
                    .text_summary_for_range::<MBTextSummary, _>(line_start..selection_end)
                    .chars as u32;
                (selection_end.row, chars_to_last_position)
            };

        Self {
            line: NonZeroU32::new(line + 1).expect("added 1"),
            character: NonZeroU32::new(character + 1).expect("added 1"),
        }
    }
}

impl CursorPosition {
    pub fn new(workspace: &Workspace) -> Self {
        Self {
            position: None,
            context: None,
            selected_count: Default::default(),
            workspace: workspace.weak_handle(),
            update_position: Task::ready(()),
            _observe_active_editor: None,
        }
    }

    fn update_position(

View on GitHub (pinned to f4178619ac)

Solutions

  1. Use saturating_add(1) so an outlandish column clamps instead of panicking
  2. Compute the column in usize and cast at the end, making overflow practically impossible
  3. Replace expect with unwrap_or(u32::MAX) plus a debug log for the impossible case
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/go_to_line/src/cursor_position.rs:63 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/4dab858dd9461b13. Report an issue: GitHub.