sxyazi/yazi · error
cannot convert to StrandBuf
Error message
cannot convert to StrandBuf
What it means
Thrown by the by-value `TryFrom<Data> for StrandBuf` when the value cannot become a strand (string-like buffer). Accepted variants are `String`, `Path`, and `Bytes`; everything else bails with "cannot convert to StrandBuf".
Source
Thrown at yazi-shared/src/data/data.rs:236
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 {
type Error = anyhow::Error;
fn try_from(value: &Data) -> Result<Self, Self::Error> {
Ok(match value {
Data::String(s) => s.to_string().into(),
Data::Path(p) => p.into_strand(),
Data::Bytes(b) => Self::Bytes(b.clone()),
_ => bail!("cannot convert to StrandBuf"),
})
}
}
impl PartialEq<bool> for Data {View on GitHub (pinned to 5f901b886b)
Solutions
- Match the variant and stringify manually where appropriate (e.g. format integers/numbers with `to_string()`).
- Fix the producer to emit `Data::String`/`Data::Path`/`Data::Bytes`.
- Convert `Data::Url` via its strand representation before wrapping in StrandBuf if URLs should be accepted.
Example fix
// before
let s: StrandBuf = data.try_into()?;
// after
let s: StrandBuf = match data {
d @ (Data::String(_) | Data::Path(_) | Data::Bytes(_)) => d.try_into()?,
Data::Integer(i) => i.to_string().into(),
other => bail!("cannot stringify {other:?}"),
}; Defensive patterns
Strategy: type-guard
Validate before calling
fn is_strand_like(data: &Data) -> bool {
matches!(data, Data::String(_) | Data::Path(_) | Data::Bytes(_))
} Type guard
fn to_strand(data: Data) -> Option<StrandBuf> {
match data {
Data::String(_) | Data::Path(_) | Data::Bytes(_) => StrandBuf::try_from(data).ok(),
_ => None,
}
} Try / catch
match StrandBuf::try_from(data) {
Ok(s) => use_strand(s),
Err(e) => log::warn!("expected text-like value: {e}"),
} Prevention
- Stringify numeric/boolean variants explicitly before requesting a StrandBuf.
- Keep Lua boundaries emitting strings, not nil or tables, for text fields.
- Use the type guard helper in all display/render paths.
When it happens
Trigger: `StrandBuf::try_from(data)` where `data` is `Data::Bool`, `Data::Integer`, `Data::Number`, `Data::Url`, `Data::Dict`, or `Data::Any`.
Common situations: Rendering or logging a fetched value that turned out to be numeric/boolean, or a Lua script passing `nil`/table where a string was required.
Related errors
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/6c1d2ee6eb0620b7.
Report an issue: GitHub.