{"record":{"id":"931f0043ca7d73ab","repo":"sxyazi/yazi","slug":"not-bytes","errorCode":null,"errorMessage":"not bytes","messagePattern":"not bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"yazi-shared/src/data/data.rs","lineNumber":223,"sourceCode":"\t\t\tData::Bytes(b) => b.as_slice().try_into(),\n\t\t\t_ => bail!(\"not a URL\"),\n\t\t}\n\t}\n}\n\nimpl TryFrom<&Data> for UrlBuf {\n\ttype Error = anyhow::Error;\n\n\tfn try_from(value: &Data) -> Result<Self, Self::Error> { UrlCow::try_from(value).map(Into::into) }\n}\n\nimpl<'a> TryFrom<&'a Data> for &'a [u8] {\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::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 {","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-shared/src/data/data.rs#L205-L241","documentation":"Thrown by `TryFrom<&Data> for &[u8]` when the `Data` is not the `Bytes` variant. Unlike the URL conversions, this one is strict: only `Data::Bytes` yields a byte slice; string and URL variants also bail with \"not bytes\".","triggerScenarios":"`<&[u8]>::try_from(&data)` where `data` is `Data::String`, `Data::Url`, `Data::Dict`, etc.","commonSituations":"Reading binary payloads (e.g. preview or fetch results) where the producer returned plain text (`Data::String`) instead of bytes, so the caller's byte-slice conversion fails.","solutions":["If the producer may return strings, match and use `Data::String(s) => s.as_bytes()` manually.","Make the producer wrap binary data in `Data::Bytes`.","Check the variant before converting: `matches!(data, Data::Bytes(_))`."],"exampleFix":"// before\nlet bytes: &[u8] = (&data).try_into()?;\n// after\nlet bytes: &[u8] = match &data {\n    Data::Bytes(b) => b,\n    Data::String(s) => s.as_bytes(),\n    other => bail!(\"expected bytes, got {other:?}\"),\n};","handlingStrategy":"type-guard","validationCode":"fn is_bytes(data: &Data) -> bool { matches!(data, Data::Bytes(_)) }","typeGuard":"fn as_bytes(data: &Data) -> Option<&[u8]> {\n    if let Data::Bytes(b) = data { Some(b) } else { None }\n}","tryCatchPattern":"match <&[u8]>::try_from(&data) {\n    Ok(bytes) => use_bytes(bytes),\n    Err(e) => log::warn!(\"expected binary payload: {e}\"),\n}","preventionTips":["Ensure binary producers wrap data in `Data::Bytes`, never `Data::String`.","Handle String variants separately with `as_bytes()` when text is possible.","Document whether each payload key carries bytes or text."],"tags":["rust","type-conversion","bytes"],"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"}