oxc-project/oxc · error

line break count must fit in u32

Error message

line break count must fit in u32

What it means

Assertion in the formatter's exact_line_breaks builder: the requested line-break count is accumulated into a u32 counter (with checked adds), so a count that does not fit in u32 cannot be represented and the builder panics up front rather than silently truncating verbatim blank-line output.

Solutions

  1. Clamp or split the break count into batches that each fit in u32
  2. Emit the blank lines via multiple exact_line_breaks calls instead of one huge count
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_formatter_core/src/write/builders.rs:75 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@1f902a6962 (2026-08-20). Data as JSON: /api/errors/8ccf1633623cae8a. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_formatter_core/src/write/builders.rs:88

/// For blank runs inside verbatim values (block scalars, block strings),
/// where the number of line breaks IS the value and must not be normalized.
/// From a mid-line position the first break ends the current line, leaving `count - 1` blank lines;
/// from the start of a line all `count` breaks become blank lines.
///
/// Unlike [hard_line_break]:
/// - the breaks always print, regardless of the current line or a preceding blank line
/// - consecutive calls accumulate, nothing is collapsed or capped
///
/// The blank lines themselves carry no indention;
/// the NEXT line starts at the current indention (same re-arming as [hard_line_break]).
///
/// # Panics
/// When `count == 0` or `count > u32::MAX`.
/// Both are unreachable from source-derived callers: a source of N bytes cannot hold more than N line breaks,
/// and sources are capped at `u32::MAX` by `oxc_span::Span`.
#[inline]
pub fn exact_line_breaks(count: usize) -> Line {
    let count = u32::try_from(count).expect("line break count must fit in u32");
    let count = std::num::NonZeroU32::new(count).expect("line break count must be >= 1");
    Line::new(LineMode::ExactLineBreaks(count))
}

/// A forced line break that starts the next line at the marked root indention (Prettier's `literalline`).
///
/// Unlike [hard_line_break]:
/// - pending whitespace on the current line materializes as-is (never dropped)
/// - the newline always prints, even on an empty line
/// - the next line starts at the [mark_as_root] indention (column 0 when unmarked)
///   instead of the current indention
///
/// Used for verbatim multi-line content whose line structure is built element by element (e.g. YAML block scalars).
/// For verbatim content held as ONE string,
/// a multiline [text] already prints its embedded newlines with these semantics.
///
/// Known divergence from Prettier:
/// a [hard_line_break] directly after a literal line is absorbed by

View on GitHub (pinned to 1f902a6962)