sxyazi/yazi · error
not a boolean
Error message
not a boolean
What it means
`TryFrom<&Data> for bool` converts a dynamic Data value into a boolean, accepting `Data::Boolean` and the string literals `"yes"`/`"no"`. Any other Data variant or string content is rejected with the terse 'not a boolean' error.
Source
Thrown at yazi-shared/src/data/data.rs:102
impl<T> FromIterator<T> for Data
where
T: Into<Self>,
{
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
Self::List(iter.into_iter().map(Into::into).collect())
}
}
impl TryFrom<&Data> for bool {
type Error = anyhow::Error;
fn try_from(value: &Data) -> Result<Self, Self::Error> {
match value {
Data::Boolean(b) => Ok(*b),
Data::String(s) if s == "no" => Ok(false),
Data::String(s) if s == "yes" => Ok(true),
_ => bail!("not a boolean"),
}
}
}
impl<'a> TryFrom<&'a Data> for &'a str {
type Error = anyhow::Error;
fn try_from(value: &'a Data) -> Result<Self, Self::Error> {
match value {
Data::String(s) => Ok(s),
_ => bail!("not a string"),
}
}
}
impl<'a> TryFrom<Data> for Cow<'a, str> {
type Error = anyhow::Error;
View on GitHub (pinned to 5f901b886b)
Solutions
- Ensure the value is an actual boolean or the exact strings `"yes"`/`"no"`
- Convert the source value to a boolean before storing it in Data
- Handle the Err case with a fallback via `.unwrap_or(false)` or report a clearer message
Example fix
// before let b: bool = data.try_into()?; // after let b: bool = data.try_into().unwrap_or(false); // or normalize "true"/"false" upstream
Defensive patterns
Strategy: type-guard
Validate before calling
fn as_bool(d: &Data) -> Option<bool> {
match d {
Data::Boolean(b) => Some(*b),
Data::String(s) => match s.as_str() { "yes" => Some(true), "no" => Some(false), _ => None },
_ => None,
}
} Type guard
fn is_bool_like(d: &Data) -> bool {
matches!(d, Data::Boolean(_)) || matches!(d, Data::String(s) if s == "yes" || s == "no")
} Try / catch
let flag = bool::try_from(&data).unwrap_or_else(|_| {
tracing::warn!("expected boolean, got {data:?}");
false
}); Prevention
- Store only real booleans or the exact strings "yes"/"no" in Data
- Normalize Lua truthiness to booleans before crossing the boundary
- Never assume numeric or "true"/"false" strings coerce to bool
When it happens
Trigger: Calling `.try_into()`/`bool::try_from(&data)` on Data holding a number, list, or any string other than exactly `yes`/`no`, e.g. converting a Lua value that was `true`/`1`/`"true"`.
Common situations: Plugin data passed from Lua where booleans became strings like `"true"`; config values written as `enabled = "maybe"`; expecting numeric truthiness coercion that this conversion does not perform.
Related errors
- not a string
- Cannot construct system event
- Kind `{kind}` must be in kebab-case
- invalid file type: {value:04o}
- not a list of Files
AI-assisted analysis of sxyazi/yazi@5f901b886b (2026-09-02).
Data as JSON: /api/errors/cc6d26af66ecb958.
Report an issue: GitHub.