gitbutlerapp/gitbutler · error
Cannot comment on : the diff is binary or too large
Error message
Cannot comment on {scope}: the diff is binary or too large What it means
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.
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
Example fix
// before
create_comment(&ctx, Comment::new(FileAnchor::Lines("assets/logo.png", 1..3), payload))?;
// after
if is_binary_or_too_large("assets/logo.png") {
eprintln!("Inline comments unsupported for binary/large files");
} else {
create_comment(&ctx, Comment::new(FileAnchor::Lines("assets/logo.png", 1..3), payload))?;
} Defensive patterns
Strategy: validation
Validate before calling
fn anchorable(path: &Path) -> bool {
!is_binary(path) && path.metadata().map(|m| m.len() < MAX_DIFF_BYTES).unwrap_or(false)
} Type guard
if let FileAnchor::Unanchorable = anchor { return Err(UnsupportedAnchor); } Try / catch
match create_comment(&ctx, comment) {
Err(e) if e.to_string().contains("binary or too large") => fallback_to_commit_comment(),
other => other?,
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Nothing to anchor a comment to in
- Aborting due to empty branch name
- Ad-hoc (single-branch) branch moves are not supported…
- An octopus merge commits must have at least two parents
- another pre-commit hook is already using the repository…
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/e4eb264e6ed922c5.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-comments/src/lib.rs:140
workspace: &but_graph::Workspace,
store: &CommentStore,
comment: NewComment,
context_lines: u32,
now_ms: i64,
) -> anyhow::Result<DiffComment> {
let scope = anchor_scope_display(&comment.commit_change_id, &comment.path);
let mut diffs = ScopeDiffs::new(repo, workspace, context_lines);
let Some(anchor) = diffs.file(comment.commit_change_id.as_deref(), &comment.path)? else {
bail!(
"Commit {} is not in the applied workspace",
comment.commit_change_id.as_deref().unwrap_or_default()
);
};
let file = match anchor {
FileAnchor::Lines(lines) => lines,
FileAnchor::Gone => bail!("Nothing to anchor a comment to in {scope}"),
FileAnchor::Unanchorable => {
bail!("Cannot comment on {scope}: the diff is binary or too large")
}
};
let line = file
.line_at(comment.side, comment.line_number)
.with_context(|| {
format!(
"No line {} on the {} side in {scope}",
comment.line_number,
comment.side.as_str(),
)
})?;
// Snapshot the same-side neighbouring lines too: they disambiguate between identical
// lines when the comment is re-located later.
let line_before = (comment.line_number > 1)
.then(|| file.line_at(comment.side, comment.line_number - 1))
.flatten()
.map(|line| line.content.clone());View on GitHub (pinned to 58e5313667)