{"record":{"id":"b0194ba4586d05cf","repo":"BoundaryML/baml","slug":"encountered-impossible-config-map-key-during-parsing","errorCode":null,"errorMessage":"Encountered impossible config map key during parsing","messagePattern":"Encountered impossible config map key during parsing","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/ast/src/parser/parse_expression.rs","lineNumber":533,"sourceCode":"\nfn parse_config_map_key(token: Pair<'_>, diagnostics: &mut Diagnostics) -> Expression {\n    assert_correct_parser(&token, &[Rule::config_map_key], diagnostics);\n\n    let span = diagnostics.span(token.as_span());\n    if let Some(current) = token.into_inner().next() {\n        return match current.as_rule() {\n            Rule::identifier => Expression::Identifier(parse_identifier(current, diagnostics)),\n            Rule::quoted_string_literal => Expression::StringValue(\n                current.into_inner().next().unwrap().as_str().to_string(),\n                span,\n            ),\n            _ => {\n                unreachable_rule(&current, \"config_map_key\", diagnostics);\n                Expression::Identifier(Identifier::Local(String::new(), span))\n            }\n        };\n    }\n    unreachable!(\"Encountered impossible config map key during parsing\")\n}\n\npub(super) fn parse_raw_string(token: Pair<'_>, diagnostics: &mut Diagnostics) -> RawString {\n    assert_correct_parser(&token, &[Rule::raw_string_literal], diagnostics);\n\n    let mut content = None;\n\n    for current in token.into_inner() {\n        match current.as_rule() {\n            Rule::raw_string_literal_content_1\n            | Rule::raw_string_literal_content_2\n            | Rule::raw_string_literal_content_3\n            | Rule::raw_string_literal_content_4\n            | Rule::raw_string_literal_content_5 => {\n                content = Some((\n                    current.as_str().to_string(),\n                    diagnostics.span(current.as_span()),\n                ));","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/ast/src/parser/parse_expression.rs#L515-L551","documentation":"This is a `unreachable!()` panic from the infix-operator mapping in `parse_expression`'s pratt parser in the BAML AST parser. The match enumerates every binary operator rule the grammar allows (EQ, NEQ, comparisons, arithmetic, BIT_XOR, BIT_SHL/SHR, OR, AND, INSTANCE_OF, etc.); receiving any other rule as an infix operator breaks the grammar/parser contract and panics. It is an internal invariant, typically triggered only by grammar/code version mismatch.","triggerScenarios":"The pratt parser's `map_infix` receives an operator Pair whose rule is not one of the mapped `Rule::*` binary operators — only possible after adding a new binary operator to baml.pest (e.g. `??`, pipeline `|>`) without adding a match arm.","commonSituations":"Using a newly introduced binary operator in BAML expressions against an older parser; contributors extending the binary-operator grammar without updating `parse_expression`; running mixed-version baml grammar and parser crates.","solutions":["Rewrite the BAML expression using only supported binary operators (==, !=, <, >, +, -, *, /, &&, ||, instanceof, etc.)","If you added a new infix operator to baml.pest, add the corresponding arm (e.g. `Rule::COALESCE => BinaryOperator::Coalesce`) in the `map_infix` match","Align grammar and parser versions by upgrading/downgrading BAML"],"exampleFix":"// before (unsupported operator)\nlet v = a ?? b;\n// after\nlet v = if a != null { a } else { b };","handlingStrategy":"validation","validationCode":"// Restrict generated BAML to known binary operators:\nconst SUPPORTED_INFIX = ['==','!=','<','>','<=','>=','+','-','*','/','%','&&','||','&','|','^','<<','>>','instanceof'];\nfunction assertSupportedBinaryOps(expr) {\n  for (const op of SUPPORTED_INFIX) { /* tokenizer-level check */ }\n  if (/\\?\\?|->|\\|>|~/.test(expr)) {\n    throw new Error('Unsupported infix operator will panic the BAML parser: ' + expr);\n  }\n}","typeGuard":"const usesOnlySupportedInfix = (expr) => !/\\?\\?|\\|>|::/.test(expr);","tryCatchPattern":"catch (panicOutput) {\n  if (String(panicOutput).includes('Unexpected infix operator')) {\n    logParserBug('grammar added an infix op missing from map_infix', panicOutput);\n    return null;\n  }\n  throw panicOutput;\n}","preventionTips":["Use only the documented BAML binary operators in expressions","Add the map_infix arm in the same PR that adds a binary operator to baml.pest","Version-align grammar and parser crates","Include every binary operator in parser snapshot tests"],"tags":["parser","panic","binary-operator","rust"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}