Aider-AI/aider · error · DiffError
Invalid patch line found in update section: {line}
Error message
Invalid patch line found in update section: {line} What it means
Raised by PatchCoder's update-section parser: while collecting patch body lines it encountered a line beginning with '***' that is not one of the recognized markers ('@@', '*** End Patch', '*** Update File:', '*** Delete File:', '*** Add File:', '*** End of File'). Inside an update body, '***' is reserved for structural markers only.
Source
Thrown at aider/coders/patch_coder.py:127
line = lines[index]
norm_line = _norm(line)
# Check for section terminators
if norm_line.startswith(
(
"@@",
"*** End Patch",
"*** Update File:",
"*** Delete File:",
"*** Add File:",
"*** End of File", # Special terminator
)
):
break
if norm_line == "***": # Legacy/alternative terminator? Handle just in case.
break
if norm_line.startswith("***"): # Invalid line
raise DiffError(f"Invalid patch line found in update section: {line}")
index += 1
last_mode = mode
# Determine line type and strip prefix
if line.startswith("+"):
mode = "add"
line_content = line[1:]
elif line.startswith("-"):
mode = "delete"
line_content = line[1:]
elif line.startswith(" "):
mode = "keep"
line_content = line[1:]
elif line.strip() == "": # Treat blank lines in patch as context ' '
mode = "keep"
line_content = "" # Keep it as a blank line
else:View on GitHub (pinned to 5dc9490bb3)
Solutions
- Remove or reword lines starting with '***' inside the update body (e.g. change '*** note' to '# note').
- Verify marker spelling exactly: '*** Update File: path', '*** End Patch', etc.
- Send the DiffError back to the model to re-emit a clean patch — PatchCoder.get_edits converts it to ValueError('Error parsing patch content: ...') for that retry loop.
- If the target file genuinely contains '***'-prefixed lines, keep them as patch body lines with a leading context space (' *** line') so they parse as kept content.
Example fix
# before *** Update File: foo.py @@ context -*** legacy banner +new code *** End Patch # after *** Update File: foo.py @@ context - *** legacy banner (prefix kept-content lines with a space) +new code *** End Patch
Defensive patterns
Strategy: validation
Validate before calling
VALID_MARKERS = ("@@", "*** End Patch", "*** Update File:", "*** Delete File:", "*** Add File:", "*** End of File")
def stray_marker_lines(patch_text: str) -> list[str]:
return [
l for l in patch_text.splitlines()
if l.strip().startswith("***") and l.strip() not in VALID_MARKERS and not l.strip().startswith(tuple(VALID_MARKERS))
] # non-empty → fix these lines before calling get_edits() Try / catch
try:
coder.get_edits(patch_text)
except ValueError as e:
if "Invalid patch line found in update section" in str(e):
patch_text = reemit_patch_without_stray_markers(str(e)) # ask the model to fix
coder.get_edits(patch_text)
else:
raise Prevention
- Escape or re-prefix any literal '***'-starting content lines in the target file with a leading context space.
- Use the exact marker vocabulary ('*** End Patch', '*** Update File: ', ...) in prompts so the model copies it verbatim.
- Run a marker lint over generated patches before applying.
When it happens
Trigger: An LLM emitting a patch (via the 'patch' edit format / apply_patch grammar) whose update section contains a stray '***'-prefixed line — e.g. a C-style comment like '*** note ***', a markdown divider, or a mistyped marker such as '*** Update-File:'.
Common situations: Models mixing apply_patch syntax with unified diff or markdown conventions; comment lines in updated code accidentally starting with '***'; typo'd section headers.
Related errors
- Invalid line prefix in update section: {line}
- Empty patch section found.
- 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/76179c35e8a3981a.
Report an issue: GitHub.