gitbutlerapp/gitbutler · warning · anyhow::Error
Cannot comment on {scope}: 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() classified the file as FileAnchor::Unanchorable: the diff for {scope} is binary or exceeds the size threshold the diff machinery allows, so no line model exists and line comments are impossible by design.
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 caf1f223d3)
Solutions
- Use a non-line-scoped comment (commit/file level) for that path instead
- Mark the file binary or exclude it from review if it is generated output
- Split the change so the file's diff fits under the size threshold
- If the file is genuinely reviewable text, check .gitattributes rules that misclassify it (e.g. -diff)
Defensive patterns
Strategy: validation
Validate before calling
// cheap pre-checks before offering line comments
let is_binary = std::fs::read(&path).is_ok_and(|b| b.contains(&0));
let too_large = std::fs::metadata(&path).map(|m| m.len() > MAX_REVIEWABLE).unwrap_or(true);
if is_binary || too_large { ui.disable_line_comments(&path); } Try / catch
match create_comment(...) {
Err(e) if e.to_string().contains("binary or too large") =>
create_file_level_note(comment).await, // degrade, don't fail
r => r?,
} Prevention
- Mark known binary/generated paths in .gitattributes so tooling can skip them
- Hide the comment button on binary or oversized diffs in the UI
- Split oversized changes so review tooling can model the diff
When it happens
Trigger: Attempting a line comment on a binary file (image, compiled artifact, lockfile marked binary) or a text file whose diff is too large for the anchored-diff representation.
Common situations: Reviewing generated files, vendored blobs, or minified bundles; large SQL/CSV data changes; users clicking 'comment' on a diff view the backend refuses to model.
Related errors
- Commit {} is not in the applied workspace
- Nothing to anchor a comment to in {scope}
- Failed to communicate with LM Studio server: ${error instanc
- When using LM Studio, you must provide a valid endpoint
- No comment with id {id}
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/e4eb264e6ed922c5.
Report an issue: GitHub.