{"record":{"id":"0d5fbf6c274d6288","repo":"sxyazi/yazi","slug":"not-a-file","errorCode":null,"errorMessage":"not a File","messagePattern":"not a File","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-fs/src/file/data.rs","lineNumber":13,"sourceCode":"use anyhow::{anyhow, bail};\nuse yazi_macro::impl_data_any;\nuse yazi_shared::data::Data;\n\nuse crate::file::{File, Files};\n\nimpl_data_any!(File, from_into_lua = inherit);\n\nimpl TryFrom<Data> for File {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: Data) -> Result<Self, Self::Error> {\n\t\tvalue.into_any::<Self>().ok_or_else(|| anyhow!(\"not a File\"))\n\t}\n}\n\nimpl TryFrom<&Data> for File {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &Data) -> Result<Self, Self::Error> {\n\t\tvalue.as_any::<Self>().cloned().ok_or_else(|| anyhow!(\"not a File\"))\n\t}\n}\n\nimpl TryFrom<Data> for Files {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: Data) -> Result<Self, Self::Error> {\n\t\tlet Data::List(files) = value else { bail!(\"not a list of Files\") };\n\t\tfiles.into_iter().map(File::try_from).collect::<Result<_, _>>().map(Self)\n\t}","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-fs/src/file/data.rs#L1-L31","documentation":"File implements TryFrom<Data>: it attempts to downcast the dynamic Data payload into a File via into_any. If the Data holds some other type (e.g. integer, string, Url, Files), the conversion fails with \"not a File\". This is a type-mismatch error at the Lua/Data boundary.","triggerScenarios":"Calling code that does File::try_from(data) where the Data was constructed from a non-File Lua value — e.g. passing a string, number, or table-of-files where a File is expected.","commonSituations":"Plugin authors passing the wrong Lua value into a Rust-exposed API; extracting a field from a Data variant assuming it is a File; API version changes where a callback now receives a different type.","solutions":["Check the actual Data variant before converting (match on the variant or use as_any::<File>()).","Pass the correct Lua object (a File instance) into the API.","Read the plugin/API docs to confirm which type the binding expects."],"exampleFix":"// before\nlet f: File = data.try_into()?;\n// after\nlet f = match data.as_any::<File>() {\n    Some(f) => f.clone(),\n    None => anyhow::bail!(\"expected a File, got another Data variant\"),\n};","handlingStrategy":"type-guard","validationCode":"-- Lua\nif not File.is(data) then error(\"expected a File value\") end","typeGuard":"// Rust\nfn as_file(data: &Data) -> Option<&File> {\n    data.as_any::<File>()\n}","tryCatchPattern":"// Rust\nmatch File::try_from(data) {\n    Ok(f) => handle(f),\n    Err(_) => { /* log and treat as wrong-type payload */ }\n}","preventionTips":["Check the expected Data variant before converting.","Keep plugin call sites in sync with the API's documented parameter types.","Use as_any::<T>() probing during development to catch type drift early."],"tags":["type-mismatch","lua-binding","data"],"backgroundTag":"type-conversion-failed","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}