sxyazi/yazi · error

not bytes

Error message

not bytes

What it means

Thrown by `TryFrom<&Data> for &[u8]` when the `Data` is not the `Bytes` variant. Unlike the URL conversions, this one is strict: only `Data::Bytes` yields a byte slice; string and URL variants also bail with "not bytes".

Source

Thrown at yazi-shared/src/data/data.rs:223

			Data::Bytes(b) => b.as_slice().try_into(),
			_ => bail!("not a URL"),
		}
	}
}

impl TryFrom<&Data> for UrlBuf {
	type Error = anyhow::Error;

	fn try_from(value: &Data) -> Result<Self, Self::Error> { UrlCow::try_from(value).map(Into::into) }
}

impl<'a> TryFrom<&'a Data> for &'a [u8] {
	type Error = anyhow::Error;

	fn try_from(value: &'a Data) -> Result<Self, Self::Error> {
		match value {
			Data::Bytes(b) => Ok(b),
			_ => bail!("not bytes"),
		}
	}
}

impl TryFrom<Data> for StrandBuf {
	type Error = anyhow::Error;

	fn try_from(value: Data) -> Result<Self, Self::Error> {
		Ok(match value {
			Data::String(s) => s.into_owned().into(),
			Data::Path(p) => p.into_strand(),
			Data::Bytes(b) => Self::Bytes(b),
			_ => bail!("cannot convert to StrandBuf"),
		})
	}
}

impl TryFrom<&Data> for StrandBuf {

View on GitHub (pinned to 5f901b886b)

Solutions

  1. If the producer may return strings, match and use `Data::String(s) => s.as_bytes()` manually.
  2. Make the producer wrap binary data in `Data::Bytes`.
  3. Check the variant before converting: `matches!(data, Data::Bytes(_))`.

Example fix

// before
let bytes: &[u8] = (&data).try_into()?;
// after
let bytes: &[u8] = match &data {
    Data::Bytes(b) => b,
    Data::String(s) => s.as_bytes(),
    other => bail!("expected bytes, got {other:?}"),
};
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_bytes(data: &Data) -> bool { matches!(data, Data::Bytes(_)) }

Type guard

fn as_bytes(data: &Data) -> Option<&[u8]> {
    if let Data::Bytes(b) = data { Some(b) } else { None }
}

Try / catch

match <&[u8]>::try_from(&data) {
    Ok(bytes) => use_bytes(bytes),
    Err(e) => log::warn!("expected binary payload: {e}"),
}

Prevention

When it happens

Trigger: `<&[u8]>::try_from(&data)` where `data` is `Data::String`, `Data::Url`, `Data::Dict`, etc.

Common situations: Reading binary payloads (e.g. preview or fetch results) where the producer returned plain text (`Data::String`) instead of bytes, so the caller's byte-slice conversion fails.

Related errors


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