sxyazi/yazi · error · io::Error

{e}

Error message

{e}

What it means

Produced by TryFrom<Vec<u8>> for Stamp when str::from_utf8 fails on the signature portion of the stamp bytes; the Utf8Error's Display becomes the whole message ('{e}', e.g. 'invalid utf-8 sequence of 1 bytes from index 2'). The stamp structure length-checked OK but its signature is not valid UTF-8.

Source

Thrown at yazi-vfs/src/stamp.rs:105

	}

	#[inline]
	pub fn sig(&self) -> &str { unsafe { str::from_utf8_unchecked(&self.0[..Self::SIG_LEN]) } }

	#[inline]
	fn name(&self) -> &[u8] { &self.0[Self::SIG_LEN..] }
}

impl TryFrom<Vec<u8>> for Stamp {
	type Error = io::Error;

	fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
		let (sig, _) = value
			.split_at_checked(Self::SIG_LEN)
			.filter(|(_, n)| !n.is_empty())
			.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidData, "Invalid cache stamp"))?;

		str::from_utf8(sig).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
		Ok(Self(value))
	}
}

View on GitHub (pinned to 8ebf930f17)

Solutions

  1. Delete the corrupt stamp file and re-create it via Stamp::write
  2. Clear the cache directory entirely to remove all invalid stamps
  3. Confirm no other process writes to Yazi's cache directory

Example fix

// before
let stamp = Stamp::try_from(bytes)?;
// after
let stamp = Stamp::try_from(bytes).inspect_err(|_| {
    tracing::warn!("dropping corrupt stamp at {}", stamp_path.display());
    let _ = std::fs::remove_file(&stamp_path);
})?;
Defensive patterns

Strategy: fallback

Validate before calling

let data = tokio::fs::read(&stamp_path).await?;
if data.len() >= Stamp::SIG_LEN && std::str::from_utf8(&data[..Stamp::SIG_LEN]).is_err() {
    std::fs::remove_file(&stamp_path).ok(); /* treat as cache miss */
}

Type guard

fn stamp_sig_is_utf8(data: &[u8]) -> bool {
    data.get(..Stamp::SIG_LEN)
        .map(|s| std::str::from_utf8(s).is_ok())
        .unwrap_or(false)
}

Try / catch

match Stamp::try_from(data) {
    Ok(s) => s,
    Err(e) if e.kind() == io::ErrorKind::InvalidData => { purge_stamp(); cache_miss() },
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Stamp::try_from(bytes) where the first SIG_LEN bytes contain non-UTF-8 data — a corrupted signature region, or bytes written by a binary format other than the expected textual signature + name layout.

Common situations: Bit-rot or partial overwrite corrupting the stamp file; mixing stamp formats across Yazi versions; another application writing into the cache directory.

Related errors


AI-assisted analysis of sxyazi/yazi@8ebf930f17 (2026-09-02). Data as JSON: /api/errors/018ad7cd8e5a905a. Report an issue: GitHub.