{"record":{"id":"ab3b94d930932638","repo":"BoundaryML/baml","slug":"expected-a","errorCode":null,"errorMessage":"Expected a {}","messagePattern":"Expected a (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/ast/src/formatter/mod.rs","lineNumber":72,"sourceCode":"                Some(pair) => {\n                    if pair.as_rule() == Rule::NEWLINE {\n                        $pairs.next();\n                        continue;\n                    }\n                    if pair.as_rule() != $rule {\n                        break Err(anyhow!(\n                            \"Expected a {:?}, got a {:?} ({}:{})\",\n                            $rule,\n                            pair.as_rule(),\n                            file!(),\n                            line!()\n                        ));\n                    } else {\n                        $pairs.next();\n                        break Ok(pair);\n                    }\n                }\n                None => break Err(anyhow!(\"Expected a {}\", stringify!($rule))),\n            }\n        }\n    }};\n\n    ($pairs:ident, $rule:expr, optional) => {{\n        match $pairs.peek() {\n            Some(pair) => {\n                if pair.as_rule() == $rule {\n                    $pairs.next()\n                } else {\n                    None\n                }\n            }\n            None => None,\n        }\n    }};\n}\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/ast/src/formatter/mod.rs#L54-L90","documentation":"The optional/required variant of next_pair! errors with 'Expected a {}' when the pair iterator is exhausted but a required rule was still expected. Note the DECLARED AS metadata shows this message string is also surfaced by CLI version-selector helpers (selector_origin etc.) in baml's main.rs, but the source shown is the formatter macro's None branch.","triggerScenarios":"A required rule expected by next_pair! is missing because the parse tree ended earlier than the formatter's structural walk anticipated — truncated or syntactically unusual (but parseable) BAML source.","commonSituations":"Formatting a partially written or truncated .baml file, or grammar/formatter version mismatch where the expected trailing rule no longer exists.","solutions":["Complete/truncate-fix the .baml source so the expected construct is present.","Use a baml-language CLI version matching the parser that produced the AST.","Report the schema snippet as a formatter bug if the file parses cleanly with baml-cli parse."],"exampleFix":"// before (truncated source)\nfunction Foo(a in\n// after\nfunction Foo(a in string) {\n  a\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let formatted = format_schema(source, &options)\n    .or_else(|_| Ok::<String, anyhow::Error>(source.to_string()))?;","preventionTips":["Don't format truncated/in-progress .baml files; complete the file first.","Version-align the CLI and library so expected rules exist.","Add a formatting smoke test over your schema files."],"tags":["rust","parser","formatting","missing-rule"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}