{"record":{"id":"492e43873d553c59","repo":"BoundaryML/baml","slug":"expected-token-node-expected-desc-but-found-found-at-at","errorCode":null,"errorMessage":"Expected token/node {expected_desc}, but found {found:?} at {at:?}","messagePattern":"Expected token/node (.+?), but found (.+?) at (.+?)","errorType":"exception","errorClass":"StrongAstError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_fmt/src/ast/mod.rs","lineNumber":51,"sourceCode":"///\n/// Helps with conveniently printing error messages.\npub trait KnownKind {\n    /// Should be constant, but we can't use `const` because it's a trait.\n    fn kind() -> SyntaxKind;\n}\n\n/// 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.","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_fmt/src/ast/mod.rs#L33-L69","documentation":"StrongAstError::UnexpectedKindDesc is like UnexpectedKind but the expectation is described in human-readable text (a Cow<'static, str>) rather than a single SyntaxKind. It fires during FromCST conversion when the child found at a position does not satisfy a descriptive expectation (e.g. 'an expression' or 'a modifier'), carrying the found kind and its range.","triggerScenarios":"FromCST strong-AST conversion encounters a child whose kind does not match a multi-kind or descriptive expectation at the conversion site — anywhere the AST builder calls expect-style helpers with a description string instead of one exact SyntaxKind.","commonSituations":"Malformed BAML source that parses into a tree the AST layer cannot interpret; grammar/parser version drift producing unexpected node shapes; programmatic construction of syntax trees with wrong children.","solutions":["Use `at` to locate and correct the offending BAML syntax in the source file","Check for parser errors before conversion; a lossy/error tree often triggers this","Align parser and baml_fmt crate versions so the CST shape matches the AST builder's expectations","If constructing trees manually, ensure children satisfy the documented expectation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check the child satisfies the descriptive expectation before conversion\nif !expected_desc_matches(child.kind()) {\n    return Err(format!(\"expected {}, found {:?}\", expected_desc, child.kind()));\n}","typeGuard":"fn matches_desc(k: SyntaxKind, desc: &str) -> bool { /* kind set for desc */ expected_desc_matches(k) }","tryCatchPattern":"match StrongAst::from_cst(node) {\n    Ok(ast) => use(ast),\n    Err(StrongAstError::UnexpectedKindDesc { expected_desc, found, at }) => {\n        report(at, format!(\"expected {expected_desc}, found {found:?}\"));\n    }\n    Err(e) => report_all(e),\n}","preventionTips":["Re-parse and clear all parser errors before formatting","Align grammar and AST-builder versions","Use `at` and `expected_desc` messages to fix source syntax precisely","Avoid hand-mutating syntax 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"}