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
- Rewrite the raw string using standard BAML raw-string syntax (`#"text"#`) with balanced delimiters
- Replace the raw string with a regular quoted string or template string if the escaping allows it
- Check the BAML source at the panic span for a truncated or malformed raw string and fix the delimiters
- 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
- Always close raw strings with the matching `"#` delimiter
- Prefer plain quoted strings when escaping is trivial
- Update parse_raw_string whenever raw_string_literal rules change in baml.pest
- Add parser tests for empty and multi-hash raw strings
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
- Encountered impossible raw string during parsing
- Name should always be defined for attribute.
- Encountered impossible doc comment during parsing: {:?}, {:?
- c_for_init_stmt cannot accept empty input
- c_for_after_stmt cannot accept empty input
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/4b8f593d4620eff6.
Report an issue: GitHub.