Aider-AI/aider · error · DiffError
Empty patch section found.
Error message
Empty patch section found.
What it means
Raised by PatchCoder when an update-file section consumed zero body lines and no '*** End of File' marker was present (index == start_index and not is_eof). The parser expects at least one patch line, chunk, or the EOF marker between section headers.
Source
Thrown at aider/coders/patch_coder.py:189
# Finalize any pending chunk at the end of the section
if del_lines or ins_lines:
chunks.append(
Chunk(
orig_index=len(context_lines) - len(del_lines),
del_lines=del_lines,
ins_lines=ins_lines,
)
)
# Check for EOF marker
is_eof = False
if index < len(lines) and _norm(lines[index]) == "*** End of File":
index += 1
is_eof = True
if index == start_index and not is_eof: # Should not happen if patch is well-formed
raise DiffError("Empty patch section found.")
return context_lines, chunks, index, is_eof
def identify_files_needed(text: str) -> List[str]:
"""Extracts file paths from Update and Delete actions."""
lines = text.splitlines()
paths = set()
for line in lines:
norm_line = _norm(line)
if norm_line.startswith("*** Update File: "):
paths.add(norm_line[len("*** Update File: ") :].strip())
elif norm_line.startswith("*** Delete File: "):
paths.add(norm_line[len("*** Delete File: ") :].strip())
return list(paths)
# --------------------------------------------------------------------------- #View on GitHub (pinned to 5dc9490bb3)
Solutions
- Provide at least one context/added/deleted line after every '*** Update File:' header, or drop the empty section entirely.
- Check for truncation if the patch ends abruptly — increase output limits.
- Retry the model with the error message so it re-emits complete sections.
- If the intent was a no-op update, remove the header rather than leaving an empty section.
Example fix
# before *** Update File: foo.py *** End Patch # after *** Update File: foo.py @@ context line -old line +new line *** End Patch
Defensive patterns
Strategy: validation
Validate before calling
def empty_update_sections(patch_text: str) -> list[str]:
lines = patch_text.splitlines()
empty, i = [], 0
while i < len(lines):
if lines[i].strip().startswith("*** Update File:"):
j, body = i + 1, 0
while j < len(lines) and not lines[j].strip().startswith("***"):
if lines[j].strip():
body += 1
j += 1
if body == 0:
empty.append(lines[i])
i = j
else:
i += 1
return empty # non-empty → drop these sections before parsing Try / catch
try:
coder.get_edits(patch_text)
except ValueError as e:
if "Empty patch section" in str(e):
patch_text = drop_or_fill_empty_sections(patch_text)
coder.get_edits(patch_text)
else:
raise Prevention
- Strip placeholder '*** Update File:' headers with no hunks before parsing.
- Check for truncated patches (no '*** End Patch' tail) — truncation often yields empty sections.
- Feed the error back so the model re-emits complete sections.
When it happens
Trigger: A '*** Update File: path' header immediately followed by another header or '*** End Patch' with no +/-/space lines in between; or two consecutive section markers with an empty body.
Common situations: Model emits an update header then forgets the hunk; degenerate/m truncated patches; placeholders like '*** Update File: foo.py' with the body accidentally stripped.
Related errors
- Invalid patch line found in update section: {line}
- Invalid line prefix in update section: {line}
- Error parsing patch content: {e}
- Unexpected error parsing patch: {e}
- Update File action missing path.
AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15).
Data as JSON: /api/errors/b51cafdb2426dc88.
Report an issue: GitHub.