{"record":{"id":"a6d9057bc938991d","repo":"gitbutlerapp/gitbutler","slug":"nothing-to-anchor-a-comment-to-in-scope","errorCode":null,"errorMessage":"Nothing to anchor a comment to in {scope}","messagePattern":"Nothing to anchor a comment to in (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"crates/but-comments/src/lib.rs","lineNumber":138,"sourceCode":"pub fn create_comment(\n    repo: &gix::Repository,\n    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))","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but-comments/src/lib.rs#L120-L156","documentation":"create_comment() mapped the file anchor to FileAnchor::Gone, meaning the diff knows about the file but there is no line content on any side to attach the comment to — typically a deleted file with nothing to anchor against. The {scope} placeholder shows commit/path context to identify which anchor failed.","triggerScenarios":"Anchoring a line comment to a file that the commit deletes, or to a side where the file does not exist (e.g. old-side line numbers of an added file after the diff drifted), so no line range can be produced.","commonSituations":"Review UIs pre-filling line numbers from a stale diff; commenting on deleted files during code review; diff context_lines too small to surface any hunk for the selected side.","solutions":["Anchor the comment to the side where the file still has content (e.g. the old side of a deletion)","If the file is genuinely gone in both displayed sides, use a commit-level/file-level note instead of a line anchor","Re-open the diff so the UI recomputes line numbers from the current hunk before submitting","Increase context_lines when constructing ScopeDiffs so adjacent hunks provide anchorable lines"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// probe the anchor before submitting\nlet mut diffs = ScopeDiffs::new(repo, workspace, context_lines);\nmatch diffs.file(comment.commit_change_id.as_deref(), &comment.path)? {\n    Some(FileAnchor::Lines(_)) => { /* safe to create the line comment */ }\n    Some(FileAnchor::Gone) => return Err(anyhow!(\"file has no lines on this side\")),\n    Some(FileAnchor::Unanchorable) => return Err(anyhow!(\"binary or oversized diff\")),\n    None => return Err(anyhow!(\"commit not in applied workspace\")),\n}","typeGuard":null,"tryCatchPattern":"// map to UI guidance rather than a raw error\nmatch create_comment(...) {\n    Err(e) if e.to_string().contains(\"Nothing to anchor\") =>\n        show_hint(\"pick a line on the side where the file exists\"),\n    r => r?,\n}","preventionTips":["Recompute line numbers from the current diff right before comment creation","Only enable line comments on sides where the file exists (old side for deletions)","Offer commit/file-level comments as the fallback affordance for deleted files"],"tags":["comments","diff","deleted-file","anchor"],"backgroundTag":"diff-anchor-missing","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}