{"record":{"id":"37215a0c72c47c81","repo":"BoundaryML/baml","slug":"baml-panics-mapkeynotfound","errorCode":"baml.panics.MapKeyNotFound","errorMessage":"key not found in map","messagePattern":"key not found in map","errorType":"error_code","errorClass":"VmPanic","httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm_types/src/errors.rs","lineNumber":45,"sourceCode":"    /// An `int` (i63) arithmetic operation overflowed the representable\n    /// range `[INT_MIN, INT_MAX]`. Carries a human-readable description of\n    /// the operation (e.g. `\"4611686018427387903 + 1\"`); built only on the\n    /// cold overflow path, so the `String` alloc never touches hot code.\n    #[error(\"integer overflow: {message}\")]\n    IntegerOverflow { message: String },\n\n    // Raised by array and byte-array subscripting, so the message stays generic\n    // (\"index\", not \"array index\").\n    #[error(\"index out of bounds: {index} of {length}\")]\n    IndexOutOfBounds { index: i64, length: usize },\n\n    #[error(\"invalid field access: field {field_index} of {field_count}\")]\n    InvalidFieldAccess {\n        field_index: usize,\n        field_count: usize,\n    },\n\n    #[error(\"key not found in map\")]\n    MapKeyNotFound,\n\n    #[error(\"stack overflow\")]\n    StackOverflow,\n\n    #[error(\"assertion failed\")]\n    AssertionFailed,\n\n    #[error(\"unreachable code executed\")]\n    Unreachable,\n\n    #[error(\"operation cancelled\")]\n    Cancelled,\n\n    /// A user-caused panic from `baml.sys.panic`, and the stdlib's panic of\n    /// record for a user-violated native invariant (e.g. a reflection kind\n    /// view's `_ty` field overwritten with a type of a different kind).\n    #[error(\"baml.sys.panic: {message}\")]","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm_types/src/errors.rs#L27-L63","documentation":"Raised when a map lookup does not find the requested key. Unlike some runtimes it returns a panic rather than an optional value, so absence of a key is treated as an exceptional condition. The error carries no payload since the key is known at the call site.","triggerScenarios":"Evaluating a map indexing instruction with a key absent from the map, e.g. `map[\"missing_key\"]` or a computed key that never matches stored keys.","commonSituations":"Typos in string keys, keys built from user input or external data with different formats (casing, whitespace), assuming a config/env map contains a key it does not.","solutions":["Check membership before indexing, or use the map API that returns an option/default value.","Normalize keys (trim/case) on both write and read sides.","Catch `baml.panics.MapKeyNotFound` and substitute a default when absence is acceptable."],"exampleFix":"// before\nlet port = config[\"port\"];\n// after\nlet port = config.get(\"port\").unwrap_or(8080);","handlingStrategy":"validation","validationCode":"// BAML: membership check before indexing\nif (config.contains(\"port\")) { let port = config[\"port\"]; }","typeGuard":null,"tryCatchPattern":"// BAML\ntry {\n  let v = map[key];\n} catch (e: baml.panics.MapKeyNotFound) {\n  let v = default;\n}","preventionTips":["Normalize keys (trim/case) on insert and lookup","Prefer APIs returning an option/default over raw indexing","Never index maps keyed by raw user input without normalization"],"tags":["vm","map","lookup","panic","baml"],"backgroundTag":"record-not-found","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"}