{"record":{"id":"55670d0591f26a8b","repo":"BoundaryML/baml","slug":"0","errorCode":null,"errorMessage":"{0:?}","messagePattern":"\\{0:\\?\\}","errorType":"exception","errorClass":"FormatterError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_fmt/src/lib.rs","lineNumber":132,"sourceCode":"    pub line_width: usize,\n    /// Indent width. Default: `4`\n    pub indent_width: usize,\n}\nimpl Default for FormatOptions {\n    fn default() -> Self {\n        Self {\n            line_width: 100,\n            indent_width: CANONICAL_INDENT_WIDTH,\n        }\n    }\n}\n\n/// Canonical indentation used by the CLI, LSP, and default library formatter.\npub const CANONICAL_INDENT_WIDTH: usize = 4;\n\n#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]\npub enum FormatterError {\n    #[error(\"{0:?}\")]\n    ParseErrors(Vec<ParseError>),\n    #[error(\"{0}\")]\n    StrongAstError(#[from] ast::StrongAstError),\n}\n\n#[cfg(test)]\nmod format_options_tests {\n    use super::*;\n\n    #[test]\n    fn default_options_use_the_canonical_four_space_indent() {\n        let options = FormatOptions::default();\n        assert_eq!(CANONICAL_INDENT_WIDTH, 4);\n        assert_eq!(options.indent_width, CANONICAL_INDENT_WIDTH);\n        let formatted = format(\"function value() -> int {\\n  result\\n}\\n\", &options)\n            .expect(\"default formatter options should format a function body\");\n        assert_eq!(formatted, \"function value() -> int {\\n    result\\n}\\n\");\n    }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_fmt/src/lib.rs#L114-L150","documentation":"FormatterError::ParseErrors wraps a Vec<ParseError> produced when the baml_fmt formatter fails to parse the input source. The formatter cannot build an AST from a lossy tree, so it collects all parse errors and returns them via this variant; the Display impl debug-prints the error list. It is the top-level formatter error for syntactically invalid BAML input.","triggerScenarios":"Calling the formatter (CLI format, LSP formatting, or library format API) on BAML source containing syntax errors — the parse step yields one or more ParseErrors which are returned wrapped in this variant.","commonSituations":"Formatting a file with typos, unclosed braces/strings, or unsupported/newer syntax; running `baml fmt` on an in-progress edit; LSP format-on-save over a broken buffer; formatting files from a newer BAML version with an older formatter.","solutions":["Fix the BAML syntax errors listed in the wrapped ParseErrors (each includes its range) before formatting","Run the parser/`baml` CLI diagnostics on the file to enumerate all errors","Upgrade baml_fmt/parser if the file uses syntax newer than the installed toolchain","Exclude generated or known-bad files from format-on-save until they are valid"],"exampleFix":"// before (unclosed string)\nprompt \"\nHello\n// after\nprompt \"\nHello\n\"","handlingStrategy":"validation","validationCode":"// before formatting, run the parser and bail on any errors\nlet (tree, errors) = parse_baml(source);\nif !errors.is_empty() {\n    return Err(FormatterError::ParseErrors(errors)); // handle before formatting\n}","typeGuard":null,"tryCatchPattern":"match format_source(source) {\n    Ok(formatted) => save(formatted),\n    Err(FormatterError::ParseErrors(errs)) => {\n        for e in errs { report_parse_error(e); }\n        // skip writing formatted output\n    }\n    Err(e) => report_other(e),\n}","preventionTips":["Fix all syntax errors before running the formatter or format-on-save","Run parser diagnostics/`baml` CLI checks in CI to catch broken files early","Disable format-on-save for buffers with active parse errors in LSP setups","Keep the BAML toolchain updated to parse newer syntax"],"tags":["parser","formatter","syntax","baml"],"backgroundTag":"json-parse-error","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}