BoundaryML/baml · error · FormatterError

{0}

Error message

{0}

What it means

FormatterError::ParseErrors is thrown by the baml_fmt formatter when the source text cannot be parsed before formatting. thiserror renders the variant with `{0:?}`, so the message is the Debug representation of the Vec<ParseError>. Formatting requires a valid AST, so all parse failures are surfaced through this variant.

Source

Thrown at baml_language/crates/baml_fmt/src/lib.rs:134

    pub indent_width: usize,
}
impl Default for FormatOptions {
    fn default() -> Self {
        Self {
            line_width: 100,
            indent_width: CANONICAL_INDENT_WIDTH,
        }
    }
}

/// Canonical indentation used by the CLI, LSP, and default library formatter.
pub const CANONICAL_INDENT_WIDTH: usize = 4;

#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum FormatterError {
    #[error("{0:?}")]
    ParseErrors(Vec<ParseError>),
    #[error("{0}")]
    StrongAstError(#[from] ast::StrongAstError),
}

#[cfg(test)]
mod format_options_tests {
    use super::*;

    #[test]
    fn default_options_use_the_canonical_four_space_indent() {
        let options = FormatOptions::default();
        assert_eq!(CANONICAL_INDENT_WIDTH, 4);
        assert_eq!(options.indent_width, CANONICAL_INDENT_WIDTH);
        let formatted = format("function value() -> int {\n  result\n}\n", &options)
            .expect("default formatter options should format a function body");
        assert_eq!(formatted, "function value() -> int {\n    result\n}\n");
    }
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Fix the underlying BAML syntax errors reported by the parse errors before formatting
  2. Run the parser or LSP diagnostics first to see the precise error locations
  3. Exclude unparseable/generated files from the formatter in CI

Example fix

// before (formatting broken source directly)
let formatted = baml_fmt::format(src)?;
// after
match parser::parse(src) {
    Ok(_) => baml_fmt::format(src)?,
    Err(errs) => eprintln!("fix syntax first: {errs:?}"),
}
Defensive patterns

Strategy: validation

Validate before calling

let parse_result = parser::parse(src);
if let Err(errs) = parse_result {
    eprintln!("cannot format, syntax errors: {errs:?}");
    return;
}

Prevention

When it happens

Trigger: Calling the formatter (e.g. format entry points in baml_fmt) on BAML source containing syntax errors; the parser produces a Vec<ParseError> which is wrapped via this variant.

Common situations: Running baml fmt on a file mid-edit; saving an incomplete BAML file with a formatter-on-save hook; CI format checks on a branch with broken syntax; a typo such as a missing brace or invalid expression.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/cdc546a4929b012c. Report an issue: GitHub.