Aider-AI/aider · error · DiffError
Invalid line prefix in update section: {line}
Error message
Invalid line prefix in update section: {line} What it means
Raised by PatchCoder's update-section parser when a body line has none of the accepted prefixes: '+' (add), '-' (delete), ' ' (keep/context), or completely blank. The parser is strict — every line in an update section must carry a diff prefix.
Source
Thrown at aider/coders/patch_coder.py:148
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:
# Assume lines without prefix are context if format is loose,
# but strict format requires ' '. Raise error for strictness.
raise DiffError(f"Invalid line prefix in update section: {line}")
# If mode changes from add/delete back to keep, finalize the previous chunk
if mode == "keep" and last_mode != "keep":
if del_lines or ins_lines:
chunks.append(
Chunk(
# orig_index is relative to the start of the *context* block found
orig_index=len(context_lines) - len(del_lines),
del_lines=del_lines,
ins_lines=ins_lines,
)
)
del_lines, ins_lines = [], []
# Collect lines based on mode
if mode == "delete":
del_lines.append(line_content)
context_lines.append(line_content) # Deleted lines are part of the original contextView on GitHub (pinned to 5dc9490bb3)
Solutions
- Prefix every line in the update section: '+' for added, '-' for removed, ' ' for unchanged context.
- Blank context lines inside a hunk should be a single space or truly empty only at section boundaries — re-check the failing line named in the error.
- Return the error to the LLM (it arrives as ValueError 'Error parsing patch content: Invalid line prefix...') so it re-emits a well-formed patch.
- Prefer the fence-free patch template in prompts/system reminders so the model doesn't wrap hunks in markdown fences.
Example fix
# before
*** Update File: foo.py
@@
def f():
return 1 (no prefix — raises)
*** End Patch
# after
*** Update File: foo.py
@@
def f():
- return 1
+ return 2
*** End Patch Defensive patterns
Strategy: validation
Validate before calling
def unprefixed_body_lines(patch_text: str) -> list[int]:
bad, in_update = [], False
for n, l in enumerate(patch_text.splitlines(), 1):
s = l.strip()
if s.startswith("*** Update File:"):
in_update = True
elif s == "*** End Patch" or s.startswith(("*** Add File:", "*** Delete File:")):
in_update = False
elif in_update and l and not l[0] in "+- " and not s.startswith(("@@", "***")):
bad.append(n)
return bad # non-empty line numbers → prefix them before parsing Try / catch
try:
coder.get_edits(patch_text)
except ValueError as e:
if "Invalid line prefix in update section" in str(e):
patch_text = reemit_with_prefixes(str(e)) # model retry with +/-/space markers
coder.get_edits(patch_text)
else:
raise Prevention
- Remind the model in the system prompt that every update-body line needs '+', '-', or ' ' prefix (blank context lines too).
- Never paste raw markdown fences inside an update section.
- Lint generated patches for unprefixed lines before calling get_edits().
When it happens
Trigger: A patch in apply_patch grammar where the model wrote raw unprefixed code lines inside the update body — e.g. pasted source without the leading +/-/space markers, or a markdown fence line slipping into the patch.
Common situations: Models blending 'patch' edit format with plain code output; users hand-authoring patches and forgetting that context lines need a leading space (including for blank context lines inside hunks, which must be ' ' not '').
Related errors
- Invalid patch line found 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/5b5a8e8060e17d45.
Report an issue: GitHub.