{"record":{"id":"cc6d26af66ecb958","repo":"sxyazi/yazi","slug":"not-a-boolean","errorCode":null,"errorMessage":"not a boolean","messagePattern":"not a boolean","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/data.rs","lineNumber":102,"sourceCode":"\nimpl<T> FromIterator<T> for Data\nwhere\n\tT: Into<Self>,\n{\n\tfn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {\n\t\tSelf::List(iter.into_iter().map(Into::into).collect())\n\t}\n}\n\nimpl TryFrom<&Data> for bool {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &Data) -> Result<Self, Self::Error> {\n\t\tmatch value {\n\t\t\tData::Boolean(b) => Ok(*b),\n\t\t\tData::String(s) if s == \"no\" => Ok(false),\n\t\t\tData::String(s) if s == \"yes\" => Ok(true),\n\t\t\t_ => bail!(\"not a boolean\"),\n\t\t}\n\t}\n}\n\nimpl<'a> TryFrom<&'a Data> for &'a str {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &'a Data) -> Result<Self, Self::Error> {\n\t\tmatch value {\n\t\t\tData::String(s) => Ok(s),\n\t\t\t_ => bail!(\"not a string\"),\n\t\t}\n\t}\n}\n\nimpl<'a> TryFrom<Data> for Cow<'a, str> {\n\ttype Error = anyhow::Error;\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/data.rs#L84-L120","documentation":"`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.","triggerScenarios":"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\"`.","commonSituations":"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.","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"],"exampleFix":"// before\nlet b: bool = data.try_into()?;\n// after\nlet b: bool = data.try_into().unwrap_or(false); // or normalize \"true\"/\"false\" upstream","handlingStrategy":"type-guard","validationCode":"fn as_bool(d: &Data) -> Option<bool> {\n    match d {\n        Data::Boolean(b) => Some(*b),\n        Data::String(s) => match s.as_str() { \"yes\" => Some(true), \"no\" => Some(false), _ => None },\n        _ => None,\n    }\n}","typeGuard":"fn is_bool_like(d: &Data) -> bool {\n    matches!(d, Data::Boolean(_)) || matches!(d, Data::String(s) if s == \"yes\" || s == \"no\")\n}","tryCatchPattern":"let flag = bool::try_from(&data).unwrap_or_else(|_| {\n    tracing::warn!(\"expected boolean, got {data:?}\");\n    false\n});","preventionTips":["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"],"tags":["type-conversion","dynamic-data","validation"],"backgroundTag":"dynamic-data-type-mismatch","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}