{"record":{"id":"6c1d2ee6eb0620b7","repo":"sxyazi/yazi","slug":"cannot-convert-to-strandbuf","errorCode":null,"errorMessage":"cannot convert to StrandBuf","messagePattern":"cannot convert to StrandBuf","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/data.rs","lineNumber":236,"sourceCode":"\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &'a Data) -> Result<Self, Self::Error> {\n\t\tmatch value {\n\t\t\tData::Bytes(b) => Ok(b),\n\t\t\t_ => bail!(\"not bytes\"),\n\t\t}\n\t}\n}\n\nimpl TryFrom<Data> for StrandBuf {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: Data) -> Result<Self, Self::Error> {\n\t\tOk(match value {\n\t\t\tData::String(s) => s.into_owned().into(),\n\t\t\tData::Path(p) => p.into_strand(),\n\t\t\tData::Bytes(b) => Self::Bytes(b),\n\t\t\t_ => bail!(\"cannot convert to StrandBuf\"),\n\t\t})\n\t}\n}\n\nimpl TryFrom<&Data> for StrandBuf {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &Data) -> Result<Self, Self::Error> {\n\t\tOk(match value {\n\t\t\tData::String(s) => s.to_string().into(),\n\t\t\tData::Path(p) => p.into_strand(),\n\t\t\tData::Bytes(b) => Self::Bytes(b.clone()),\n\t\t\t_ => bail!(\"cannot convert to StrandBuf\"),\n\t\t})\n\t}\n}\n\nimpl PartialEq<bool> for Data {","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/data.rs#L218-L254","documentation":"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\".","triggerScenarios":"`StrandBuf::try_from(data)` where `data` is `Data::Bool`, `Data::Integer`, `Data::Number`, `Data::Url`, `Data::Dict`, or `Data::Any`.","commonSituations":"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.","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."],"exampleFix":"// before\nlet s: StrandBuf = data.try_into()?;\n// after\nlet s: StrandBuf = match data {\n    d @ (Data::String(_) | Data::Path(_) | Data::Bytes(_)) => d.try_into()?,\n    Data::Integer(i) => i.to_string().into(),\n    other => bail!(\"cannot stringify {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"fn is_strand_like(data: &Data) -> bool {\n    matches!(data, Data::String(_) | Data::Path(_) | Data::Bytes(_))\n}","typeGuard":"fn to_strand(data: Data) -> Option<StrandBuf> {\n    match data {\n        Data::String(_) | Data::Path(_) | Data::Bytes(_) => StrandBuf::try_from(data).ok(),\n        _ => None,\n    }\n}","tryCatchPattern":"match StrandBuf::try_from(data) {\n    Ok(s) => use_strand(s),\n    Err(e) => log::warn!(\"expected text-like value: {e}\"),\n}","preventionTips":["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."],"tags":["rust","type-conversion","string"],"backgroundTag":"type-conversion-failed","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}