sxyazi/yazi · error · io::Error

InvalidInput

InvalidInput

Error message

invalid trash entry

What it means

Input validation in `TrashId::new`: the trash entry's top-level directory is empty or the entry's relative path is not relative, so the pair cannot form a valid (root, name) trash identifier. This is a constructor guard for internal trash bookkeeping; the faulting inputs are `top` and `rel`.

Source

Thrown at yazi-fs/src/trash/trash_id.rs:23

use yazi_shim::path::PathExt;

#[derive(Clone, Debug)]
pub(crate) struct TrashId {
	top: PathBuf,
	rel: PathBuf,
}

impl TrashId {
	pub(super) fn new<T, R>(top: T, rel: R) -> io::Result<Self>
	where
		T: Into<PathBuf>,
		R: Into<PathBuf>,
	{
		let top = top.into();
		let rel = rel.into();

		if top.as_os_str().is_empty() || !rel.is_relative() {
			return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid trash entry"));
		}
		if rel.has_parent_component() {
			return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid trash entry path"));
		}

		Ok(Self { top, rel })
	}

	pub(super) fn top(&self) -> &Path { &self.top }

	pub(super) fn rel(&self) -> &Path { &self.rel }

	#[cfg(target_os = "macos")]
	pub(super) fn path(&self) -> PathBuf {
		if self.has_rel() { self.top.join(&self.rel) } else { self.top.clone() }
	}

	pub(super) fn child(&self, name: &OsStr) -> io::Result<Self> {

View on GitHub (pinned to 5f901b886b)

Solutions

  1. Ensure top is a non-empty path to the item inside the trash
  2. Pass rel as a bare relative path (e.g. 'sub/file.txt') without a leading separator
  3. Validate inputs before constructing the id

Example fix

// before
TrashId::new("", Path::new("/abs/rel"))?
// after
TrashId::new("/Users/me/.Trash/item", Path::new("rel"))?
Defensive patterns

Strategy: validation

Validate before calling

fn valid_parts(top: &OsStr, rel: &Path) -> bool {
    !top.is_empty() && rel.is_relative()
}

Type guard

fn is_relative_bare(p: &Path) -> bool { p.is_relative() && !p.as_os_str().is_empty() }

Try / catch

match TrashId::new(top, rel) {
    Err(e) if e.kind() == io::ErrorKind::InvalidInput => fix_paths_and_retry(),
    other => other,
}

Prevention

When it happens

Trigger: Calling TrashId::new with an empty top path string, or with a rel argument that is absolute (starts with '/' or a root/prefix component).

Common situations: Building ids programmatically from user input or URLs where the rel segment accidentally includes an absolute path, or an empty top after stripping a prefix.

Related errors


AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02). Data as JSON: /api/errors/39d409cacdedafc0. Report an issue: GitHub.