oxc-project/oxc · error

Alignment count must be a non-zero number.

Error message

Alignment count must be a non-zero number.

What it means

Panic in the formatter's align builder: the count is converted with NonZeroU8::new(count).expect(...), so align(0, ...) is rejected. Zero-space alignment is a no-op and almost always indicates a caller bug, hence the hard failure.

Source

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

        f.debug_tuple("Dedent").field(&"{{content}}").finish()
    }
}

// ---------------------------------------------------------------------------
// Align
// ---------------------------------------------------------------------------

/// Aligns its content by indenting the content by `count` spaces.
///
/// # Panics
///
/// Panics if `count` is `0`.
pub fn align<'ast, C, Content>(count: u8, content: &Content) -> Align<'_, 'ast, C>
where
    Content: Format<'ast, C>,
{
    Align {
        count: NonZeroU8::new(count).expect("Alignment count must be a non-zero number."),
        content: Argument::new(content),
    }
}

#[derive(Copy, Clone)]
pub struct Align<'a, 'ast, C> {
    count: NonZeroU8,
    content: Argument<'a, 'ast, C>,
}

impl<'ast, C> Format<'ast, C> for Align<'_, 'ast, C> {
    fn fmt(&self, f: &mut Formatter<'_, 'ast, C>) {
        f.write_element(FormatElement::Tag(StartAlign(tag::Align(self.count))));
        Arguments::from(&self.content).fmt(f);
        f.write_element(FormatElement::Tag(EndAlign));
    }
}

View on GitHub (pinned to 5b3e335484)

Solutions

  1. Remove the align wrapper when no extra indentation is needed
  2. Pass a count of at least 1
  3. Use indent or a NonZeroU8 parameter at the call site to make zero unrepresentable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_formatter_core/src/write/builders.rs:588 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/b56303d92a4ffd2c. Report an issue: GitHub.