{"record":{"id":"72177b149dbd5ad0","repo":"BoundaryML/baml","slug":"map-get-or-insert-should-be-dispatched-via-glue-get-or","errorCode":null,"errorMessage":"Map.get_or_insert: should be dispatched via __glue_get_or_insert","messagePattern":"Map\\.get_or_insert: should be dispatched via __glue_get_or_insert","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/map.rs","lineNumber":111,"sourceCode":"    }\n\n    // ── get_or_insert ─────────────────────────────────────────────────────────\n\n    fn __glue_get_or_insert(vm: &mut BexVm, args: &[Value]) -> NativeCallResult {\n        let result: NativeFunctionResult = (|| {\n            let key_as_string = vm.as_string(&args[1])?.clone();\n            let default = args[2];\n            let mut map = vm.as_map_mut(&args[0])?;\n            Ok(*map.entry(key_as_string).or_insert(default))\n        })();\n        match result {\n            Ok(v) => NativeCallResult::Done(v),\n            Err(e) => NativeCallResult::Error(e),\n        }\n    }\n\n    fn get_or_insert(_map: &mut IndexMap<BexStr, Value>, _key: &Value, _default: &Value) -> Value {\n        unreachable!(\"Map.get_or_insert: should be dispatched via __glue_get_or_insert\")\n    }\n\n    // ── clear ─────────────────────────────────────────────────────────────────\n\n    #[allow(clippy::unused_unit)]\n    fn clear(map: &mut IndexMap<BexStr, Value>) -> () {\n        map.clear();\n    }\n}\n","sourceCodeStart":93,"sourceCodeEnd":121,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/map.rs#L93-L121","documentation":"`Map.get_or_insert` is a placeholder that always panics: this operation must be dispatched via the `__glue_get_or_insert` glue method, which can allocate new entries inside the VM. The raw function exists only to fill the native-function table and must never be called.","triggerScenarios":"Dispatch routing `Map.get_or_insert` to the raw placeholder instead of `__glue_get_or_insert`, due to a misregistered native method name in the map package.","commonSituations":"VM development or custom glue dispatch layers that bypass the __glue_ naming convention for map operations.","solutions":["Fix the dispatch table so `Map.get_or_insert` resolves to `__glue_get_or_insert`.","Call get_or_insert through the normal BAML map API surface.","Rebuild/upgrade bex_vm if a released build exhibits this panic."],"exampleFix":"// before\n\"get_or_insert\" => NativeFn::Raw(map::get_or_insert),\n// after\n\"get_or_insert\" => NativeFn::Glue(map::__glue_get_or_insert),","handlingStrategy":"validation","validationCode":"assert!(dispatch_table.get(\"get_or_insert\") == Some(&NativeFn::Glue(map::__glue_get_or_insert)));","typeGuard":null,"tryCatchPattern":"// Rust panic — cover the dispatch table with a registration unit test.","preventionTips":["Call get_or_insert only via the BAML map API surface.","Pin every map method to its __glue_* implementation in tests.","Don't invoke raw placeholder native functions from embeddings."],"tags":["rust","map","dispatch","panic"],"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-23T08:17:48.524Z"}