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

  1. Check the file type/size before enabling inline commenting in the UI and disable it for binary or oversized files
  2. Fall back to a commit-level or file-level comment that does not need line anchors
  3. Increase the diff size threshold if the default is too small for your workflow
  4. 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

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


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)