{"record":{"id":"d69a8a068e6cdf85","repo":"bevyengine/bevy","slug":"attempted-to-push-invalid-value-of-type-d69a8a","errorCode":null,"errorMessage":"Attempted to push invalid value of type {}.","messagePattern":"Attempted to push invalid value of type (.+?)\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_reflect/src/impls/smallvec.rs","lineNumber":53,"sourceCode":"        let value = value.try_take::<T::Item>().unwrap_or_else(|value| {\n            <T as SmallArray>::Item::from_reflect(&*value).unwrap_or_else(|| {\n                panic!(\n                    \"Attempted to insert invalid value of type {}.\",\n                    value.reflect_type_path()\n                )\n            })\n        });\n        SmallVec::insert(self, index, value);\n    }\n\n    fn remove(&mut self, index: usize) -> Box<dyn PartialReflect> {\n        Box::new(self.remove(index))\n    }\n\n    fn push(&mut self, value: Box<dyn PartialReflect>) {\n        let value = value.try_take::<T::Item>().unwrap_or_else(|value| {\n            <T as SmallArray>::Item::from_reflect(&*value).unwrap_or_else(|| {\n                panic!(\n                    \"Attempted to push invalid value of type {}.\",\n                    value.reflect_type_path()\n                )\n            })\n        });\n        SmallVec::push(self, value);\n    }\n\n    fn pop(&mut self) -> Option<Box<dyn PartialReflect>> {\n        self.pop()\n            .map(|value| Box::new(value) as Box<dyn PartialReflect>)\n    }\n\n    fn len(&self) -> usize {\n        <SmallVec<T>>::len(self)\n    }\n\n    fn iter(&self) -> ListIter<'_> {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/src/impls/smallvec.rs#L35-L71","documentation":"The List implementation for smallvec::SmallVec<T> recovers pushed elements with value.try_take::<T::Item>() plus a <T as SmallArray>::Item::from_reflect(&*value) fallback. List::push panics with this message when the boxed value is neither the array's Item type nor FromReflect-convertible to it.","triggerScenarios":"Calling List::push on a reflected SmallVec with a mismatched element, e.g. pushing Box::new(\"x\") onto a SmallVec<[u32; 16]>.","commonSituations":"Editor/inspector appending elements; scene or network data appended into small-buffer component fields; interop code pushing host-typed values without conversion.","solutions":["Push values of the exact Item type (verify via reflect_type_path()).","Convert before pushing: Item::from_reflect(&*value), then push the converted value.","Use the typed SmallVec::push after downcasting with try_downcast_mut::<SmallVec<T>>().","Add a type gate in shared code that funnels Box<dyn PartialReflect> into lists."],"exampleFix":"// before\nsv.push(Box::new(1_u8)); // SmallVec<[u32; 16]> -> panics\n\n// after\nsv.push(Box::new(1_u32));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"use bevy_reflect::{FromReflect, PartialReflect};\n\nfn push_item_ok<I: FromReflect>(value: &dyn PartialReflect) -> bool {\n    value.try_downcast_ref::<I>().is_some() || I::from_reflect(value).is_some()\n}\n\nif push_item_ok::<u32>(boxed.as_ref()) {\n    sv.push(boxed);\n}","tryCatchPattern":null,"preventionTips":["Route erased pushes through a guard on T::Item before calling List::push.","Prefer typed SmallVec::push after try_downcast_mut."],"tags":["rust","bevy","bevy-reflect","smallvec","list","push","panic","type-mismatch"],"backgroundTag":"runtime-type-mismatch","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}