{"record":{"id":"15050b6cab1481e5","repo":"bevyengine/bevy","slug":"attempted-to-clone-invalid-key-of-type","errorCode":null,"errorMessage":"Attempted to clone invalid key of type {}.","messagePattern":"Attempted to clone invalid key of type (.+?)\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_reflect/src/impls/indexmap.rs","lineNumber":66,"sourceCode":"            .map(|(key, value)| {\n                (\n                    Box::new(key) as Box<dyn PartialReflect>,\n                    Box::new(value) as Box<dyn PartialReflect>,\n                )\n            })\n            .collect()\n    }\n\n    fn retain(&mut self, f: &mut dyn FnMut(&dyn PartialReflect, &mut dyn PartialReflect) -> bool) {\n        self.retain(move |key, value| f(key, value));\n    }\n\n    fn to_dynamic_map(&self) -> Result<DynamicMap, ReflectCloneError> {\n        let mut dynamic_map = DynamicMap::default();\n        dynamic_map.set_represented_type(PartialReflect::get_represented_type_info(self));\n        for (k, v) in self {\n            let key = K::from_reflect(k).unwrap_or_else(|| {\n                panic!(\n                    \"Attempted to clone invalid key of type {}.\",\n                    k.reflect_type_path()\n                )\n            });\n            dynamic_map.insert_boxed(Box::new(key), v.to_dynamic()?);\n        }\n        Ok(dynamic_map)\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()","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/src/impls/indexmap.rs#L48-L84","documentation":"Panic in the reflected Map impl for IndexMap's to_dynamic_map: a key could not be cloned via K::from_reflect because its reflected value does not match K. The offending key's type path is in the message; ensure the map's keys are correctly reflected as K.","triggerScenarios":"Thrown at crates/bevy_reflect/src/impls/indexmap.rs:66 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the key type K implements FromReflect","Avoid to_dynamic_map for maps with non-reflectable keys"],"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"}