{"record":{"id":"ea2756542bcfcb76","repo":"bevyengine/bevy","slug":"attempted-to-insert-invalid-key-of-type","errorCode":null,"errorMessage":"Attempted to insert invalid key of type {}.","messagePattern":"Attempted to insert invalid key of type (.+?)\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_reflect/src/impls/alloc/collections/btree/map.rs","lineNumber":68,"sourceCode":"            result.push((\n                Box::new(k) as Box<dyn PartialReflect>,\n                Box::new(v) as Box<dyn PartialReflect>,\n            ));\n        }\n        result\n    }\n\n    fn retain(&mut self, f: &mut dyn FnMut(&dyn PartialReflect, &mut dyn PartialReflect) -> bool) {\n        self.retain(move |k, v| f(k, v));\n    }\n\n    fn insert_boxed(\n        &mut self,\n        key: Box<dyn PartialReflect>,\n        value: Box<dyn PartialReflect>,\n    ) -> Option<Box<dyn PartialReflect>> {\n        let key = K::take_from_reflect(key).unwrap_or_else(|key| {\n            panic!(\n                \"Attempted to insert invalid key of type {}.\",\n                key.reflect_type_path()\n            )\n        });\n        let value = V::take_from_reflect(value).unwrap_or_else(|value| {\n            panic!(\n                \"Attempted to insert invalid value of type {}.\",\n                value.reflect_type_path()\n            )\n        });\n        self.insert(key, value)\n            .map(|old_value| Box::new(old_value) as Box<dyn PartialReflect>)\n    }\n\n    fn remove(&mut self, key: &dyn PartialReflect) -> Option<Box<dyn PartialReflect>> {\n        let mut from_reflect = None;\n        key.try_downcast_ref::<K>()\n            .or_else(|| {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/src/impls/alloc/collections/btree/map.rs#L50-L86","documentation":"Panic in the reflected Map insert_boxed for BTreeMap: the key could not be converted from its reflected form into K (take_from_reflect failed), i.e. it is not a valid K. Insert keys of the map's declared key type; the offending type path is in the message.","triggerScenarios":"Thrown at crates/bevy_reflect/src/impls/alloc/collections/btree/map.rs:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Insert a key of the map's key type K","Ensure K implements FromReflect"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}