sxyazi/yazi · error

Unsupported OS for trash operation

Error message

Unsupported OS for trash operation

What it means

Local::trash moves a file to the OS trash via the `trash` crate. On Android (target_os = "android") there is no supported trash backend, so the implementation deliberately returns io::ErrorKind::Unsupported with "Unsupported OS for trash operation". This is a compile-time platform limitation, not a runtime misconfiguration.

Solutions

  1. Use permanent deletion instead of trash on Android, or skip the trash option in the UI on this platform (cfg-gate the feature).
  2. Implement a userspace trash (move files to an app-private .Trash directory) as a fallback on Android.
  3. Catch io::ErrorKind::Unsupported from the trash call and surface a clear 'not supported on this OS' message to the user.

Example fix

// before
file.trash().await?;
// after
if cfg!(target_os = "android") {
    return Err(anyhow!("moving to trash is not supported on Android; delete permanently instead"));
}
file.trash().await?;
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust
let trash_supported = !cfg!(target_os = "android");

Try / catch

match file.trash().await {
    Err(e) if e.kind() == std::io::ErrorKind::Unsupported => ui.notify("Trash is not supported on this OS"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling trash() on a file handle while the code is compiled for Android (target_os = "android"), e.g. via a delete-to-trash operation from the file manager or a `delete --permanent=false` style flow.

Common situations: Running yazi on Android (e.g. via Termux) and issuing a trash/delete operation; CI or cross-compilation targeting android and exercising the trash code path in tests.

Related errors


AI-assisted analysis of sxyazi/yazi@a541adde4e (2026-09-02). Data as JSON: /api/errors/6f8b213f00793898. Report an issue: GitHub.

Appendix: source

Thrown at yazi-fs/src/engine/local/local.rs:197

		{
			tokio::fs::symlink_file(original, self.path).await
		}
	}

	#[inline]
	async fn symlink_metadata(&self) -> io::Result<Cha> {
		Ok(Cha::new(
			self.path.file_name().unwrap_or_default(),
			tokio::fs::symlink_metadata(self.path).await?,
		))
	}

	async fn trash(&self) -> io::Result<()> {
		let path = self.path.to_owned();
		tokio::task::spawn_blocking(move || {
			#[cfg(target_os = "android")]
			{
				Err(io::Error::new(io::ErrorKind::Unsupported, "Unsupported OS for trash operation"))
			}
			#[cfg(target_os = "macos")]
			{
				use trash::{TrashContext, macos::{DeleteMethod, TrashContextExtMacos}};
				let mut ctx = TrashContext::default();
				ctx.set_delete_method(DeleteMethod::NsFileManager);
				ctx.delete(path).map_err(io::Error::other)
			}
			#[cfg(all(not(target_os = "macos"), not(target_os = "android")))]
			{
				trash::delete(path).map_err(io::Error::other)
			}
		})
		.await?
	}

	#[inline]
	fn url(&self) -> Url<'_> { self.url }

View on GitHub (pinned to a541adde4e)