{"record":{"id":"bc6e92a4124bd4ea","repo":"bevyengine/bevy","slug":"attempted-to-push-invalid-value-of-type-bc6e92","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/macros/list.rs","lineNumber":33,"sourceCode":"                fn insert(&mut self, index: usize, value: bevy_platform::prelude::Box<dyn $crate::reflect::PartialReflect>) {\n                    let value = value.try_take::<T>().unwrap_or_else(|value| {\n                        T::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                    $insert(self, index, value);\n                }\n\n                fn remove(&mut self, index: usize) -> bevy_platform::prelude::Box<dyn $crate::reflect::PartialReflect> {\n                    bevy_platform::prelude::Box::new($remove(self, index))\n                }\n\n                fn push(&mut self, value: bevy_platform::prelude::Box<dyn $crate::reflect::PartialReflect>) {\n                    let value = T::take_from_reflect(value).unwrap_or_else(|value| {\n                        panic!(\n                            \"Attempted to push invalid value of type {}.\",\n                            value.reflect_type_path()\n                        )\n                    });\n                    $push(self, value);\n                }\n\n                fn pop(&mut self) -> Option<bevy_platform::prelude::Box<dyn $crate::reflect::PartialReflect>> {\n                    $pop(self).map(|value| bevy_platform::prelude::Box::new(value) as bevy_platform::prelude::Box<dyn $crate::reflect::PartialReflect>)\n                }\n\n                #[inline]\n                fn len(&self) -> usize {\n                    <$sub>::len(self)\n                }\n\n                #[inline]\n                fn iter(&self) -> $crate::list::ListIter<'_>  {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/src/impls/macros/list.rs#L15-L51","documentation":"The macro-generated List::push(Box<dyn PartialReflect>) for reflected list types recovers the element with T::take_from_reflect: an owning downcast to T, with a FromReflect fallback for dynamic values. Pushing a boxed value that is neither T nor convertible panics with this message naming the value's type path.","triggerScenarios":"Calling List::push on a reflected list (Vec<T>, VecDeque<T>, etc.) with a mismatched boxed value, e.g. pushing Box::new(\"text\") onto a Vec<usize>, or a dynamic value whose represented type is not T.","commonSituations":"Building lists dynamically from deserialized or network data; scripting/REPL bridges pushing host-language values into reflected Rust lists; copy logic that re-boxes elements from a list with a different element type.","solutions":["Push a value of the exact element type T (verify with reflect_type_path() on the boxed value).","Convert the incoming value first: T::from_reflect(&*value) or an explicit Into/TryFrom, then push.","Use the typed API: downcast to &mut Vec<T> and call Vec::push for compile-time guarantees.","Guard shared helper code that accepts Box<dyn PartialReflect> with an element-type check before pushing."],"exampleFix":"// before\nlist.push(Box::new(3_i64)); // Vec<f32> -> panics\n\n// after\nlet v = f32::from_reflect(&*boxed_value).expect(\"expected f32 element\");\nlist.push(Box::new(v));","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"use bevy_reflect::{FromReflect, PartialReflect};\n\nfn push_ok<T: FromReflect>(value: &dyn PartialReflect) -> bool {\n    value.try_downcast_ref::<T>().is_some() || T::from_reflect(value).is_some()\n}\n\nif push_ok::<f32>(value.as_ref()) {\n    list.push(value);\n}","tryCatchPattern":null,"preventionTips":["Downcast to the concrete Vec<T>/list type and use its typed push when possible.","Guard shared code that accepts Box<dyn PartialReflect> with an element-type check before pushing."],"tags":["rust","bevy","bevy-reflect","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"}