sxyazi/yazi · error
not a File
Error message
not a File
What it means
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.
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.
Example fix
// before
let f: File = data.try_into()?;
// after
let f = match data.as_any::<File>() {
Some(f) => f.clone(),
None => anyhow::bail!("expected a File, got another Data variant"),
}; Defensive patterns
Strategy: type-guard
Validate before calling
-- Lua
if not File.is(data) then error("expected a File value") end Type guard
// Rust
fn as_file(data: &Data) -> Option<&File> {
data.as_any::<File>()
} Try / catch
// Rust
match File::try_from(data) {
Ok(f) => handle(f),
Err(_) => { /* log and treat as wrong-type payload */ }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/0d5fbf6c274d6288.
Report an issue: GitHub.
Appendix: source
Thrown at yazi-fs/src/file/data.rs:13
use anyhow::{anyhow, bail};
use yazi_macro::impl_data_any;
use yazi_shared::data::Data;
use crate::file::{File, Files};
impl_data_any!(File, from_into_lua = inherit);
impl TryFrom<Data> for File {
type Error = anyhow::Error;
fn try_from(value: Data) -> Result<Self, Self::Error> {
value.into_any::<Self>().ok_or_else(|| anyhow!("not a File"))
}
}
impl TryFrom<&Data> for File {
type Error = anyhow::Error;
fn try_from(value: &Data) -> Result<Self, Self::Error> {
value.as_any::<Self>().cloned().ok_or_else(|| anyhow!("not a File"))
}
}
impl TryFrom<Data> for Files {
type Error = anyhow::Error;
fn try_from(value: Data) -> Result<Self, Self::Error> {
let Data::List(files) = value else { bail!("not a list of Files") };
files.into_iter().map(File::try_from).collect::<Result<_, _>>().map(Self)
}View on GitHub (pinned to 5f901b886b)