oxc-project/oxc · error

line break count must be >= 1

Error message

line break count must be >= 1

What it means

Assertion in exact_line_breaks: unlike hard_line_break, this builder guarantees the breaks always print, so a count of 0 (which would print nothing and break that contract) is rejected via expect before the element is built.

Source

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

/// 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
/// the printer's "only print a newline if the line isn't already empty" rule

View on GitHub (pinned to 5b3e335484)

Solutions

  1. Skip the exact_line_breaks call entirely when the count is 0
  2. Use if count > 0 { ... } around the builder call
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@5b3e335484 (2026-08-20). Data as JSON: /api/errors/df99bcbb0ae9e8e7. Report an issue: GitHub.