{"record":{"id":"e4eb264e6ed922c5","repo":"gitbutlerapp/gitbutler","slug":"cannot-comment-on-scope-the-diff-is-binary-or-t","errorCode":null,"errorMessage":"Cannot comment on {scope}: the diff is binary or too large","messagePattern":"Cannot comment on (.+?): the diff is binary or too large","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-comments/src/lib.rs","lineNumber":140,"sourceCode":"    workspace: &but_graph::Workspace,\n    store: &CommentStore,\n    comment: NewComment,\n    context_lines: u32,\n    now_ms: i64,\n) -> anyhow::Result<DiffComment> {\n    let scope = anchor_scope_display(&comment.commit_change_id, &comment.path);\n    let mut diffs = ScopeDiffs::new(repo, workspace, context_lines);\n    let Some(anchor) = diffs.file(comment.commit_change_id.as_deref(), &comment.path)? else {\n        bail!(\n            \"Commit {} is not in the applied workspace\",\n            comment.commit_change_id.as_deref().unwrap_or_default()\n        );\n    };\n    let file = match anchor {\n        FileAnchor::Lines(lines) => lines,\n        FileAnchor::Gone => bail!(\"Nothing to anchor a comment to in {scope}\"),\n        FileAnchor::Unanchorable => {\n            bail!(\"Cannot comment on {scope}: the diff is binary or too large\")\n        }\n    };\n    let line = file\n        .line_at(comment.side, comment.line_number)\n        .with_context(|| {\n            format!(\n                \"No line {} on the {} side in {scope}\",\n                comment.line_number,\n                comment.side.as_str(),\n            )\n        })?;\n\n    // Snapshot the same-side neighbouring lines too: they disambiguate between identical\n    // lines when the comment is re-located later.\n    let line_before = (comment.line_number > 1)\n        .then(|| file.line_at(comment.side, comment.line_number - 1))\n        .flatten()\n        .map(|line| line.content.clone());","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-comments/src/lib.rs#L122-L158","documentation":"create_comment() rejects comments whose target file's diff is binary or too large to represent as line-based text. Since line-anchored comments need line content via line_at(), the library bails with FileAnchor::Unanchorable rather than producing an anchor that cannot resolve lines.","triggerScenarios":"Calling create_comment with a file anchor on a file whose workspace diff is binary (images, compiled artifacts, lockfiles with NUL bytes) or exceeds the size threshold used during anchor resolution.","commonSituations":"A user clicks a comment button on a PNG or a minified bundle in the review UI; an auto-generated large file appears in the workspace and the UI still allows opening the comment composer.","solutions":["Check the file type/size before enabling inline commenting in the UI and disable it for binary or oversized files","Fall back to a commit-level or file-level comment that does not need line anchors","Increase the diff size threshold if the default is too small for your workflow","Filter out binary extensions from anchorable paths"],"exampleFix":"// before\ncreate_comment(&ctx, Comment::new(FileAnchor::Lines(\"assets/logo.png\", 1..3), payload))?;\n// after\nif is_binary_or_too_large(\"assets/logo.png\") {\n    eprintln!(\"Inline comments unsupported for binary/large files\");\n} else {\n    create_comment(&ctx, Comment::new(FileAnchor::Lines(\"assets/logo.png\", 1..3), payload))?;\n}","handlingStrategy":"validation","validationCode":"fn anchorable(path: &Path) -> bool {\n    !is_binary(path) && path.metadata().map(|m| m.len() < MAX_DIFF_BYTES).unwrap_or(false)\n}","typeGuard":"if let FileAnchor::Unanchorable = anchor { return Err(UnsupportedAnchor); }","tryCatchPattern":"match create_comment(&ctx, comment) {\n    Err(e) if e.to_string().contains(\"binary or too large\") => fallback_to_commit_comment(),\n    other => other?,\n}","preventionTips":["Detect binary content (NUL-byte sniff) before offering line comments","Enforce a size cap client-side matching the library threshold","Use file-level comments for non-text assets","Keep generated/large artifacts out of anchored review flows"],"tags":["git","comments","binary-files"],"backgroundTag":"unsupported-operation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}