{"record":{"id":"efaccc9ee23ae5d1","repo":"BoundaryML/baml","slug":"unexpected-additional-element-at-at-in-parent","errorCode":null,"errorMessage":"Unexpected additional element at {at:?} in {parent:?}","messagePattern":"Unexpected additional element at (.+?) in (.+?)","errorType":"exception","errorClass":"StrongAstError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_fmt/src/ast/mod.rs","lineNumber":70,"sourceCode":"    UnexpectedKindDesc {\n        expected_desc: Cow<'static, str>,\n        found: SyntaxKind,\n        at: TextRange,\n    },\n    /// When an element is expected (of a specific [`SyntaxKind`]) but there were no more children left.\n    #[error(\"Expected token/node of kind {expected:?}, but was unable to find it in {parent:?}\")]\n    MissingExpectedElement {\n        expected: SyntaxKind,\n        parent: TextRange,\n    },\n    /// When an element is expected (not of a single specific [`SyntaxKind`]) but there were no more children left.\n    #[error(\"Expected token/node {desc}, but was unable to find it in {parent:?}\")]\n    MissingExpectedElementDesc {\n        desc: Cow<'static, str>,\n        parent: TextRange,\n    },\n    /// When the node isn't expected to have any more children (e.g. a statement found a `;`) but there are still children left.\n    #[error(\"Unexpected additional element at {at:?} in {parent:?}\")]\n    UnexpectedAdditionalElement { parent: TextRange, at: TextRange },\n    /// When an element is expected to be a node but it's actually a token.\n    #[error(\"An element at {at:?} was a node when it should have been a token.\")]\n    ShouldBeNode { at: TextRange },\n    /// When an element is expected to be a token but it's actually a node.\n    #[error(\"An element at {at:?} was a token when it should have been a node.\")]\n    ShouldBeToken { at: TextRange },\n}\nimpl StrongAstError {\n    /// Checks that the given node is of the specified [`SyntaxKind`].\n    ///\n    /// # Errors\n    /// Returns [`StrongAstError::UnexpectedKind`] if the element not the expected kind.\n    pub fn assert_kind_node(node: &SyntaxNode, expected: SyntaxKind) -> Result<(), Self> {\n        if node.kind() == expected {\n            Ok(())\n        } else {\n            Err(Self::UnexpectedKind {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_fmt/src/ast/mod.rs#L52-L88","documentation":"StrongAstError::UnexpectedAdditionalElement is raised when a node should have no more children (e.g. a statement finished parsing) but leftover children remain in the parent. This indicates the CST contains more elements than the strong-AST grammar consumes — a shape violation between the parser output and the AST builder's expectations.","triggerScenarios":"During FromCST conversion, after an AST element is fully constructed, another child is still present at `at` inside the parent (`parent` TextRange) — e.g. an extra `;`, stray token, or duplicated node left in the tree.","commonSituations":"Stray/duplicated tokens in BAML source; parser producing nodes with extra trailing children; grammar updates adding new node kinds not yet handled by the strong-AST builder.","solutions":["Inspect the source at the `at` TextRange and remove the extraneous token/element","Re-parse and fix parser errors; stray tokens often result from typos (e.g. double semicolons)","Update baml_fmt alongside any parser grammar changes so new child kinds are consumed","If mutating trees programmatically, strip leftover children before conversion"],"exampleFix":"// before\nlet x = 1;;\n// after\nlet x = 1;","handlingStrategy":"validation","validationCode":"// after building the element, assert no leftover children remain\nif node.children_with_tokens().next().is_some() {\n    return Err(\"unexpected leftover children in node\");\n}","typeGuard":null,"tryCatchPattern":"match StrongAst::from_cst(node) {\n    Ok(ast) => use(ast),\n    Err(StrongAstError::UnexpectedAdditionalElement { parent, at }) => {\n        report(at, format!(\"extra element in node at {parent:?}\"));\n    }\n    Err(e) => report_all(e),\n}","preventionTips":["Remove stray/duplicate tokens (e.g. double semicolons) from BAML source","Update baml_fmt when parser grammar adds new child kinds","Fix parser errors before conversion","Strip leftover children from programmatically built trees"],"tags":["parser","ast","syntax","formatter"],"backgroundTag":"schema-validation-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}