BoundaryML/baml · error

Unexpected infix operator: {:?}

Error message

Unexpected infix operator: {:?}

What it means

This is a `unreachable!()` panic in `parse_raw_string` in the BAML AST parser. After looping over the children of a `raw_string_literal` pair, the function asserts it captured a `(content, span)` tuple; reaching the fallback means no child assigned content — the raw-string grammar produced a node with no recognized content token, breaking the grammar/parser contract. It indicates the raw string literal parsed to an empty/unrecognized shape.

Source

Thrown at engine/baml-lib/ast/src/parser/parse_expression.rs:154

                Rule::NEQ => BinaryOperator::Neq,
                Rule::LT => BinaryOperator::Lt,
                Rule::LTEQ => BinaryOperator::LtEq,
                Rule::GT => BinaryOperator::Gt,
                Rule::GTEQ => BinaryOperator::GtEq,
                Rule::ADD => BinaryOperator::Add,
                Rule::SUB => BinaryOperator::Sub,
                Rule::MUL => BinaryOperator::Mul,
                Rule::DIV => BinaryOperator::Div,
                Rule::MOD => BinaryOperator::Mod,
                Rule::BIT_AND => BinaryOperator::BitAnd,
                Rule::BIT_OR => BinaryOperator::BitOr,
                Rule::BIT_XOR => BinaryOperator::BitXor,
                Rule::BIT_SHL => BinaryOperator::Shl,
                Rule::BIT_SHR => BinaryOperator::Shr,
                Rule::OR => BinaryOperator::Or,
                Rule::AND => BinaryOperator::And,
                Rule::INSTANCE_OF => BinaryOperator::InstanceOf,
                _ => unreachable!("Unexpected infix operator: {:?}", operator.as_rule()),
            };

            Some(Expression::BinaryOperation {
                left: Box::new(left?),
                operator,
                right: Box::new(right?),
                span: span.clone(),
            })
        });

    parser.parse(token.into_inner())
}

fn parse_primary_expression(
    token: Pair<'_>,
    diagnostics: &mut internal_baml_diagnostics::Diagnostics,
) -> Option<Expression> {
    let span = diagnostics.span(token.as_span());

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Rewrite the raw string using standard BAML raw-string syntax (`#"text"#`) with balanced delimiters
  2. Replace the raw string with a regular quoted string or template string if the escaping allows it
  3. Check the BAML source at the panic span for a truncated or malformed raw string and fix the delimiters
  4. If you are a contributor: extend `parse_raw_string`'s loop to handle all child rules of `raw_string_literal` in baml.pest

Example fix

// before (malformed raw string)
let s #"unterminated
// after
let s #"terminated"#
Defensive patterns

Strategy: validation

Validate before calling

// Validate raw string delimiters are balanced before parsing:
function assertBalancedRawString(src) {
  const opens = (src.match(/#"/g) || []).length;
  const closes = (src.match(/"#/g) || []).length;
  if (opens !== closes) {
    throw new Error(`Unbalanced raw string delimiters will crash the BAML parser: ${src}`);
  }
}

Type guard

const isWellFormedRawString = (s) => /^#"[\s\S]*"#$/.test(s.trim());

Try / catch

catch (panicOutput) {
  if (String(panicOutput).includes('Encountered impossible raw string')) {
    logParserBug('raw_string_literal yielded no content', panicOutput);
    return null;
  }
  throw panicOutput;
}

Prevention

When it happens

Trigger: Parsing a raw string literal (e.g. `#"..."#`) whose `raw_string_literal` pair contains only rules not matched inside the loop — possible after a grammar change to the raw-string rules without updating `parse_raw_string`, or a zero-child raw_string_literal pair.

Common situations: Using raw string syntax with unusual hash counts or delimiters in a BAML version where raw-string lexing changed; contributors editing baml.pest raw_string_literal rules without updating the parser; corrupted/empty string token reaching the parser.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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