{"record":{"id":"24a8de8fd57d0682","repo":"BoundaryML/baml","slug":"expected-token-node-desc-but-was-unable-to-find-it-in-parent","errorCode":null,"errorMessage":"Expected token/node {desc}, but was unable to find it in {parent:?}","messagePattern":"Expected token/node (.+?), 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":64,"sourceCode":"        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.\")]\n    ShouldBeToken { at: TextRange },\n}\nimpl StrongAstError {\n    /// Checks that the given node is of the specified [`SyntaxKind`].\n    ///\n    /// # Errors","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_fmt/src/ast/mod.rs#L46-L82","documentation":"StrongAstError::MissingExpectedElementDesc is the descriptive-text variant of MissingExpectedElement: the builder expected some element described by `desc` (not a single specific SyntaxKind) but the parent node had no children remaining. It reports the description and the parent's TextRange.","triggerScenarios":"FromCST conversion reaches the end of a parent node's children while a required, descriptively-specified element is still needed — e.g. expecting 'an expression' or 'a type annotation' but the iterator is empty.","commonSituations":"Truncated BAML expressions/statements in source files; parser recovery omitting subtrees; version drift between the parser grammar and the strong-AST builder.","solutions":["Read `desc` and `parent` to determine which element is missing and add it to the BAML source","Fix all parser-reported errors before running the formatter so trees are complete","Keep parser/baml_fmt versions in sync","Validate programmatically built trees contain all mandatory children"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm the descriptively-required element exists before conversion\nif !has_required_element(parent, desc) {\n    return Err(format!(\"missing {desc}\"));\n}","typeGuard":null,"tryCatchPattern":"match StrongAst::from_cst(node) {\n    Ok(ast) => use(ast),\n    Err(StrongAstError::MissingExpectedElementDesc { desc, parent }) => {\n        report(parent, format!(\"missing {desc}\"));\n    }\n    Err(e) => report_all(e),\n}","preventionTips":["Fix truncated expressions/statements in source before formatting","Resolve parser errors first so recovery doesn't drop subtrees","Sync parser and formatter crate versions","Validate programmatically built trees for required elements"],"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"}