{"record":{"id":"5a2008305eab6212","repo":"GitoxideLabs/gitoxide","slug":"binary-data-at-path-cannot-be-diffed","errorCode":null,"errorMessage":"Binary data at {path} cannot be diffed","messagePattern":"Binary data at (.+?) cannot be diffed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"gitoxide-core/src/repository/cat.rs","lineNumber":51,"sourceCode":"                        &object.data,\n                        path,\n                        &mut |_path, attrs| {\n                            let _ = platform.matching_attributes(attrs);\n                        },\n                        to_worktree::Options {\n                            can_delay: Delay::Forbid,\n                            unknown_encoding: to_worktree::UnknownEncoding::Fail,\n                        },\n                    )?;\n                    std::io::copy(&mut converted, &mut out)?;\n                }\n                (BlobFormat::Diff | BlobFormat::DiffOrGit, cache) => {\n                    cache.set_resource(id.detach(), mode.kind(), path, ResourceKind::OldOrSource, &repo.objects)?;\n                    let resource = cache.resource(ResourceKind::OldOrSource).expect(\"just set\");\n                    let data = resource\n                        .data\n                        .as_slice()\n                        .ok_or_else(|| anyhow!(\"Binary data at {path} cannot be diffed\"))?;\n                    out.write_all(data)?;\n                }\n            }\n        }\n        _ => out.write_all(&id.object()?.data)?,\n    }\n    Ok(())\n}\n\npub(super) mod function {\n    use crate::repository::revision::resolve::TreeMode;\n\n    pub fn cat(repo: gix::Repository, revspec: &str, out: impl std::io::Write) -> anyhow::Result<()> {\n        super::display_object(&repo, repo.rev_parse(revspec)?, TreeMode::Pretty, None, out)?;\n        Ok(())\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gitoxide-core/src/repository/cat.rs#L33-L69","documentation":"Thrown by `display_object` in `gix repo cat` when diffing a blob whose content is binary (detected during diff resource cache preparation), so no text diff data is available to write out. Only text data can be produced for `BlobFormat::Diff` output.","triggerScenarios":"Running `gix repo cat <blob> --format diff` (or DiffOrGit resolved to Diff) where the blob's bytes are classified as binary (contains NUL or fails text detection) by the diff cache.","commonSituations":"Trying to diff compiled artifacts, images, PNG/JPEG files, or any NUL-containing files stored in the repo; viewing old binary blobs in history.","solutions":["Use the plain blob format instead of diff, e.g. `gix repo cat <blob>` without the diff option, to dump raw bytes","Configure a text conversion (gitattributes `diff` driver / filter) if the binary has a textual representation","Check the blob content type first (`file <path>` or `gix repo cat <blob> | file -`) before requesting a diff"],"exampleFix":"// before\ngix repo cat image.png --format diff\n// after\ngix repo cat image.png  # raw output, no diff","handlingStrategy":"fallback","validationCode":"// cheap binary sniff before requesting a diff\nfn looks_binary(bytes: &[u8]) -> bool {\n    bytes.iter().take(8000).any(|&b| b == 0)\n}","typeGuard":"fn diffable(data: Option<&[u8]>) -> bool {\n    data.is_some() && !data.unwrap().iter().take(8000).any(|&b| b == 0)\n}","tryCatchPattern":"match cat_diff(blob) {\n    Err(e) if e.to_string().contains(\"cannot be diffed\") => {\n        // fall back to raw blob output\n        out.write_all(&blob.object()?.data)?;\n    }\n    other => other?,\n}","preventionTips":["Mark binary files with `binary` in `.gitattributes` and avoid diff output for them","Sniff for NUL bytes before choosing the diff format"],"tags":["diff","binary-data","blob","cat","gitoxide"],"backgroundTag":"unsupported-operation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}