Skip to content

Commit af934d0

Browse files
committed
Replace unwrap with panic
1 parent 767dc2a commit af934d0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

crates/bevy_reflect/src/serde/serialize_with_registry.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ impl ReflectSerializeWithRegistry {
8383
impl<T: Reflect + SerializeWithRegistry> FromType<T> for ReflectSerializeWithRegistry {
8484
fn from_type() -> Self {
8585
Self {
86-
serialize: |value, registry| {
87-
let value = value.downcast_ref::<T>().unwrap();
86+
serialize: |value: &dyn Reflect, registry| {
87+
let value = value.downcast_ref::<T>().unwrap_or_else(|| {
88+
panic!(
89+
"Expected value to be of type {:?} but received {:?}",
90+
std::any::type_name::<T>(),
91+
value.reflect_type_path()
92+
)
93+
});
8894
Box::new(SerializableWithRegistry { value, registry })
8995
},
9096
}

0 commit comments

Comments
 (0)