{"record":{"id":"853fe6923c884202","repo":"sxyazi/yazi","slug":"not-a-string","errorCode":null,"errorMessage":"not a string","messagePattern":"not a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/data.rs","lineNumber":113,"sourceCode":"\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\n\tfn try_from(value: Data) -> Result<Self, Self::Error> {\n\t\tmatch value {\n\t\t\tData::String(Cow::Borrowed(s)) => Ok(Cow::Borrowed(s)),\n\t\t\tData::String(Cow::Owned(s)) => Ok(Cow::Owned(s)),\n\t\t\t_ => Err(anyhow!(\"not a string\")),\n\t\t}\n\t}\n}\n\nimpl<'a> TryFrom<&'a Data> for Cow<'a, str> {\n\ttype Error = anyhow::Error;","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/data.rs#L95-L131","documentation":"Type-conversion guard in `TryFrom<&Data> for &str`: the `Data` value being converted is not the `String` variant, so it cannot be borrowed as a string slice. The faulting input is the Data value (e.g. a Boolean, Number, or Table passed where text was required).","triggerScenarios":"Converting a Data value to `&str` when it holds a Boolean, a number, or a container variant instead of a String — commonly after `data.get(\"field\")` where the field is not a string.","commonSituations":"Reading dynamic action/plugin payload fields assuming they are strings while callers passed numbers or booleans; Lua numbers (e.g. ids) that were not converted to strings.","solutions":["Ensure the producer stores a `Data::String` (convert with `.to_string()` at the source)","Match on the Data variant yourself and handle non-string cases explicitly","Use a helper like `as_str()`/try_into with a fallback value"],"exampleFix":"// before\nlet s: &str = field.try_into()?;\n// after\nlet s: &str = field.try_into().map_err(|_| anyhow::anyhow!(\"expected string field, got {field:?}\"))?;","handlingStrategy":"type-guard","validationCode":"fn as_str(d: &Data) -> Option<&str> {\n    match d { Data::String(s) => Some(s), _ => None }\n}","typeGuard":"fn is_string(d: &Data) -> bool { matches!(d, Data::String(_)) }","tryCatchPattern":"let s = <&str>::try_from(&data).map_err(|_| anyhow!(\"expected string, got {data:?}\"))?;","preventionTips":["Match on the Data variant before assuming a string","Convert numbers/booleans to strings at the producer side","Validate payload field types against a schema"],"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-23T08:17:48.524Z"}