BoundaryML/baml · error · StrongAstError

Expected token/node {desc}, but was unable to find it in {pa

Error message

Expected token/node {desc}, but was unable to find it in {parent:?}

What it means

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.

Source

Thrown at baml_language/crates/baml_fmt/src/ast/mod.rs:64

        expected: SyntaxKind,
        found: SyntaxKind,
        at: TextRange,
    },
    /// When an element is expected but was found to be of a different kind.
    #[error("Expected token/node {expected_desc}, but found {found:?} at {at:?}")]
    UnexpectedKindDesc {
        expected_desc: Cow<'static, str>,
        found: SyntaxKind,
        at: TextRange,
    },
    /// When an element is expected (of a specific [`SyntaxKind`]) but there were no more children left.
    #[error("Expected token/node of kind {expected:?}, but was unable to find it in {parent:?}")]
    MissingExpectedElement {
        expected: SyntaxKind,
        parent: TextRange,
    },
    /// When an element is expected (not of a single specific [`SyntaxKind`]) but there were no more children left.
    #[error("Expected token/node {desc}, but was unable to find it in {parent:?}")]
    MissingExpectedElementDesc {
        desc: Cow<'static, str>,
        parent: TextRange,
    },
    /// When the node isn't expected to have any more children (e.g. a statement found a `;`) but there are still children left.
    #[error("Unexpected additional element at {at:?} in {parent:?}")]
    UnexpectedAdditionalElement { parent: TextRange, at: TextRange },
    /// When an element is expected to be a node but it's actually a token.
    #[error("An element at {at:?} was a node when it should have been a token.")]
    ShouldBeNode { at: TextRange },
    /// When an element is expected to be a token but it's actually a node.
    #[error("An element at {at:?} was a token when it should have been a node.")]
    ShouldBeToken { at: TextRange },
}
impl StrongAstError {
    /// Checks that the given node is of the specified [`SyntaxKind`].
    ///
    /// # Errors

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Read `desc` and `parent` to determine which element is missing and add it to the BAML source
  2. Fix all parser-reported errors before running the formatter so trees are complete
  3. Keep parser/baml_fmt versions in sync
  4. Validate programmatically built trees contain all mandatory children
Defensive patterns

Strategy: validation

Validate before calling

// confirm the descriptively-required element exists before conversion
if !has_required_element(parent, desc) {
    return Err(format!("missing {desc}"));
}

Try / catch

match StrongAst::from_cst(node) {
    Ok(ast) => use(ast),
    Err(StrongAstError::MissingExpectedElementDesc { desc, parent }) => {
        report(parent, format!("missing {desc}"));
    }
    Err(e) => report_all(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: Truncated BAML expressions/statements in source files; parser recovery omitting subtrees; version drift between the parser grammar and the strong-AST builder.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/24a8de8fd57d0682. Report an issue: GitHub.