{"record":{"id":"c99f9755e95929b6","repo":"BoundaryML/baml","slug":"map-delete-should-be-dispatched-via-glue-delete","errorCode":null,"errorMessage":"Map.delete: should be dispatched via __glue_delete","messagePattern":"Map\\.delete: should be dispatched via __glue_delete","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/map.rs","lineNumber":92,"sourceCode":"        let result: NativeFunctionResult = (|| {\n            let key_as_string = vm.as_string(&args[1])?.clone();\n            let mut map = vm.as_map_mut(&args[0])?;\n            // `shift_remove` preserves the order of remaining entries (matching\n            // insertion order) — important since `keys()` / `values()` return\n            // entries in insertion order.\n            Ok(match map.shift_remove(key_as_string.as_str()) {\n                Some(prev) => prev,\n                None => Value::NULL,\n            })\n        })();\n        match result {\n            Ok(v) => NativeCallResult::Done(v),\n            Err(e) => NativeCallResult::Error(e),\n        }\n    }\n\n    fn delete(_map: &mut IndexMap<BexStr, Value>, _key: &Value) -> Option<Value> {\n        unreachable!(\"Map.delete: should be dispatched via __glue_delete\")\n    }\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 {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/map.rs#L74-L110","documentation":"`Map.delete` is a placeholder that always panics: deletion must be dispatched via the `__glue_delete` glue method, which owns the mutable VM access required to remove entries. The raw `delete` function only exists as a table placeholder and must never be invoked.","triggerScenarios":"Method dispatch routing `Map.delete` to the raw function instead of `__glue_delete` — caused by misregistration of the native method table in the map package.","commonSituations":"VM development/patches to the map package registration; custom embeddings invoking native map functions directly by name.","solutions":["Fix the dispatch table so `Map.delete` resolves to `__glue_delete`.","In BAML code, use map delete syntax (map.remove(key) or equivalent) rather than raw native calls.","Rebuild/upgrade bex_vm if seen in a released build."],"exampleFix":"// before\n\"delete\" => NativeFn::Raw(map::delete),\n// after\n\"delete\" => NativeFn::Glue(map::__glue_delete),","handlingStrategy":"validation","validationCode":"assert!(dispatch_table.get(\"delete\") == Some(&NativeFn::Glue(map::__glue_delete)));","typeGuard":null,"tryCatchPattern":"// Rust panic — guard via a startup registration test for map methods.","preventionTips":["Route map deletes through __glue_delete.","Keep a unit test pinning the map dispatch table to __glue_* implementations.","Avoid custom dispatch layers that bypass the __glue_ convention."],"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"}