{"record":{"id":"dd9d92a9e92d94ec","repo":"bevyengine/bevy","slug":"kind-mismatch-expected-expected-received-re","errorCode":null,"errorMessage":"kind mismatch: expected {expected:?}, received {received:?}","messagePattern":"kind mismatch: expected (.+?), received (.+?)","errorType":"exception","errorClass":"TypeInfoError","httpStatus":null,"severity":"error","filePath":"crates/bevy_reflect/src/info/error.rs","lineNumber":12,"sourceCode":"use crate::ReflectKind;\nuse thiserror::Error;\n\n/// A [`TypeInfo`]-specific error.\n///\n/// [`TypeInfo`]: crate::info::TypeInfo\n#[derive(Debug, Error)]\npub enum TypeInfoError {\n    /// Caused when a type was expected to be of a certain [kind], but was not.\n    ///\n    /// [kind]: ReflectKind\n    #[error(\"kind mismatch: expected {expected:?}, received {received:?}\")]\n    KindMismatch {\n        /// Expected kind.\n        expected: ReflectKind,\n        /// Received kind.\n        received: ReflectKind,\n    },\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_reflect/src/info/error.rs#L1-L20","documentation":"TypeInfo describes a reflected type's shape (StructInfo, MapInfo, ListInfo, ...). The generated convenience casts TypeInfo::as_struct/as_tuple_struct/as_tuple/as_list/as_array/as_map/as_set/as_enum/as_opaque return Result<&XxxInfo, TypeInfoError>, and the error's KindMismatch variant reports expected vs received ReflectKind when the info is a different kind (e.g. calling as_struct on Vec<i32>, which is a List).","triggerScenarios":"Calling a TypeInfo::as_* cast whose target kind does not match the actual type: type_info().as_map() on a Vec, registration.type_info().as_struct() on an enum, etc.","commonSituations":"Registry/tooling code that iterates registered types and assumes a kind; serializers or inspectors switching on TypeInfo but forgetting variants; refactors that change a component from struct to enum or add generics that alter kind.","solutions":["Match on info.kind() (or the TypeInfo enum itself) first and handle every arm instead of assuming one kind.","Use the typed data when available: prefer ReflectRef (reflect_ref()) for value-level access, or store the expected kind next to the lookup.","Handle the Err case of as_* with a fallback instead of unwrap/expect.","If a specific kind was genuinely intended, fix the caller: the type being inspected is of the 'received' kind shown in the message."],"exampleFix":"// before\nlet info = <Vec<i32> as Typed>::type_info();\nlet s = info.as_struct().unwrap(); // KindMismatch: expected Struct, received List\n\n// after\nmatch <Vec<i32> as Typed>::type_info() {\n    TypeInfo::List(li) => println!(\"item: {:?}\", li.type_item()),\n    other => println!(\"unexpected kind: {:?}\", other.kind()),\n}","handlingStrategy":"try-catch","validationCode":"let info = registration.type_info();\nif info.kind() == ReflectKind::Map {\n    let map_info = info.as_map().expect(\"kind checked above\");\n    // ...\n}","typeGuard":"fn is_map_info(info: &TypeInfo) -> bool {\n    info.kind() == ReflectKind::Map\n}","tryCatchPattern":"match typed_type.type_info().as_map() {\n    Ok(map_info) => { /* handle map info */ }\n    Err(TypeInfoError::KindMismatch { expected, received }) => {\n        warn!(\"expected {expected:?}, got {received:?}; skipping type\");\n    }\n}","preventionTips":["Switch on info.kind() or match the TypeInfo enum instead of assuming one variant.","Cover all kind arms in registry-driven tools so refactors that change a type's kind fail soft, not loud."],"tags":["rust","bevy","bevy-reflect","typeinfo","kind-mismatch","as-cast"],"backgroundTag":"reflection-kind-mismatch","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"}