{"record":{"id":"3614171616ba65e0","repo":"BoundaryML/baml","slug":"expected-token-node-of-kind-expected-but-was-unable-to-find","errorCode":null,"errorMessage":"Expected token/node of kind {expected:?}, but was unable to find it in {parent:?}","messagePattern":"Expected token/node of kind (.+?), but was unable to find it in (.+?)","errorType":"exception","errorClass":"StrongAstError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_fmt/src/ast/mod.rs","lineNumber":58,"sourceCode":"/// Errors that can occur when parsing from a [`SyntaxNode`] with [`FromCST`].\n#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]\npub enum StrongAstError {\n    /// When an element is expected (of a specific [`SyntaxKind`]) but was found to be of a different kind.\n    #[error(\"Expected token/node of kind {expected:?}, but found {found:?} at {at:?}\")]\n    UnexpectedKind {\n        expected: SyntaxKind,\n        found: SyntaxKind,\n        at: TextRange,\n    },\n    /// When an element is expected but was found to be of a different kind.\n    #[error(\"Expected token/node {expected_desc}, but found {found:?} at {at:?}\")]\n    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.\")]","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_fmt/src/ast/mod.rs#L40-L76","documentation":"StrongAstError::MissingExpectedElement is raised during FromCST conversion when the builder requires a child of a specific SyntaxKind but the parent node has no more children left to consume. It reports the expected kind and the parent node's TextRange so the missing element can be located.","triggerScenarios":"A strongly-typed AST conversion helper iterates the parent's children expecting a required token/node (e.g. a closing brace, identifier, or keyword) but the child iterator is exhausted — the tree is truncated or missing mandatory children.","commonSituations":"Incomplete BAML source (e.g. unclosed block) that still yields a tree; parser recovery dropping required tokens; older/newer grammar producing trees without elements the current AST builder requires.","solutions":["Examine the parent TextRange and add the missing syntax element in the BAML source (e.g. the missing token/keyword)","Re-parse the file and check the parser's error list — fix reported syntax errors first","Match parser and formatter crate versions to avoid grammar-shape drift","If building trees programmatically, always append required children before conversion"],"exampleFix":"// before\nfunction Foo(param: int) {\n// after\nfunction Foo(param: int) {\n  ...\n} // include all required tokens/children","handlingStrategy":"validation","validationCode":"// ensure the parent still has the required child before consuming\nif parent.children().count() < required_children {\n    return Err(\"truncated tree: missing required element\");\n}","typeGuard":null,"tryCatchPattern":"match StrongAst::from_cst(node) {\n    Ok(ast) => use(ast),\n    Err(StrongAstError::MissingExpectedElement { expected, parent }) => {\n        report(parent, format!(\"missing {expected:?}\"));\n    }\n    Err(e) => report_all(e),\n}","preventionTips":["Complete the BAML syntax (close braces, add required tokens) before formatting","Check parser error output for truncated trees","Keep parser/formatter versions in sync","When building trees programmatically, append all mandatory children"],"tags":["parser","ast","syntax","formatter"],"backgroundTag":"missing-required-argument","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"}