{"record":{"id":"cdd512bb8168e536","repo":"sxyazi/yazi","slug":"failed-to-downcast-data-into","errorCode":null,"errorMessage":"Failed to downcast Data into {}","messagePattern":"Failed to downcast Data into (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/data.rs","lineNumber":287,"sourceCode":"\t\t\t_ => None,\n\t\t}\n\t}\n\n\tpub fn into_any<T: 'static>(self) -> Option<T> {\n\t\tmatch self {\n\t\t\tSelf::Any(a) => a.downcast::<T>().ok().map(|b| *b),\n\t\t\t_ => None,\n\t\t}\n\t}\n\n\t// FIXME: find a better name\n\tpub fn into_any2<T: 'static>(self) -> Result<T> {\n\t\tif let Self::Any(a) = self\n\t\t\t&& let Ok(t) = a.downcast::<T>()\n\t\t{\n\t\t\tOk(*t)\n\t\t} else {\n\t\t\tbail!(\"Failed to downcast Data into {}\", std::any::type_name::<T>())\n\t\t}\n\t}\n}\n\nimpl_into_integer!(Data, i8, i16, i32, i64, isize, u8, u16, u32, u64, usize, crate::id::Id);\nimpl_into_number!(Data, f32, f64);\n","sourceCodeStart":269,"sourceCodeEnd":294,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/data.rs#L269-L294","documentation":"Thrown by `Data::into_any2::<T>()` when the value is not `Data::Any` or the boxed value inside cannot be downcast to `T`. The message includes the requested type name, e.g. \"Failed to downcast Data into yazi_shared::fs::File\". This is a runtime type check on the type-erased `Any` payload.","triggerScenarios":"Calling `data.into_any2::<SomeType>()` where (a) `data` is a plain variant like `String`/`Dict`, or (b) it is `Data::Any` but holds a different concrete type than requested.","commonSituations":"Plugin message payloads fetched with the wrong generic parameter, or two code paths agreeing on a key but not on the payload type (e.g. `Vec<String>` vs `String`).","solutions":["Check the concrete type with `matches!(data, Data::Any(_))` and verify the producer's payload type; pass the matching generic to `into_any2`.","If multiple types are possible, try `into_any2::<T>()` for each candidate and fall back.","Log `std::any::type_name::<T>()` and the actual payload type at the producer to align both sides."],"exampleFix":"// before\nlet files: Vec<File> = data.into_any2()?;\n// after\nlet files: Vec<File> = data\n    .into_any2::<Vec<File>>()\n    .with_context(|| format!(\"unexpected payload: {data:?}\"))?;","handlingStrategy":"try-catch","validationCode":"fn can_downcast<T: 'static>(data: &Data) -> bool {\n    matches!(data, Data::Any(_)) // exact inner type checkable only at conversion site\n}","typeGuard":"// Data::Any hides the inner type; guard by attempting the downcast without consuming:\nfn peek<T: 'static + Clone>(data: &Data) -> Option<T> {\n    if let Data::Any(a) = data { a.downcast_ref::<T>().cloned() } else { None }\n}","tryCatchPattern":"match data.into_any2::<Vec<File>>() {\n    Ok(v) => use_files(v),\n    Err(e) => log::warn!(\"payload type mismatch: {e}; data was {data:?}\"),\n}","preventionTips":["Keep a single source of truth for payload types per message/keys.","Prefer concrete Data variants over Data::Any when the type is known.","Test producer/consumer pairs so the generic parameter stays aligned."],"tags":["rust","downcast","any","type-mismatch"],"backgroundTag":"failed-downcast","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}