{"record":{"id":"a95c778230fb557f","repo":"zed-industries/zed","slug":"couldn-t-resolve-hunk","errorCode":null,"errorMessage":"couldn't resolve hunk","messagePattern":"couldn't resolve hunk","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeta_prompt/src/udiff.rs","lineNumber":413,"sourceCode":"    let mut line_delta = 0i64;\n\n    while let Some(event) = diff.next().context(\"Failed to parse diff\")? {\n        match event {\n            DiffEvent::Hunk {\n                mut hunk,\n                path: _,\n                status: _,\n            } => {\n                let candidates = find_context_candidates(&text, &mut hunk);\n                let adjusted_start_line = hunk\n                    .start_line\n                    .and_then(|start_line| u32::try_from(start_line as i64 + line_delta).ok());\n\n                let hunk_offset =\n                    disambiguate_by_line_number(&candidates, adjusted_start_line, &|offset| {\n                        text[..offset].matches('\\n').count() as u32\n                    })\n                    .ok_or_else(|| anyhow!(\"couldn't resolve hunk\"))?;\n\n                if first_hunk_offset.is_none() {\n                    first_hunk_offset = Some(hunk_offset);\n                }\n\n                let mut hunk_line_delta = 0i64;\n                for edit in hunk.edits.iter().rev() {\n                    let range = (hunk_offset + edit.range.start)..(hunk_offset + edit.range.end);\n                    let deleted_lines = text[range.clone()].matches('\\n').count() as i64;\n                    let inserted_lines = edit.text.matches('\\n').count() as i64;\n                    text.replace_range(range, &edit.text);\n                    hunk_line_delta += inserted_lines - deleted_lines;\n                }\n                line_delta += hunk_line_delta;\n            }\n            DiffEvent::FileEnd { .. } => {\n                line_delta = 0;\n            }","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/zeta_prompt/src/udiff.rs#L395-L431","documentation":"A parsed udiff hunk could not be matched to any location in the target text: neither context-line search nor line-number disambiguation produced a usable offset in apply_diff_to_string_with_hunk_offset. Usually means the diff context no longer matches the buffer (stale text or earlier hunks shifted lines).","triggerScenarios":"Thrown at crates/zeta_prompt/src/udiff.rs:413 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate the diff against the current buffer contents and reapply","Fall back to fuzzy/whitespace-relaxed context matching before giving up","Track cumulative line_delta across hunks so later hunks resolve against already-patched text"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}