Aider-AI/aider · error · DiffError
Invalid Add File line (missing '+'): {line}
Error message
Invalid Add File line (missing '+'): {line} What it means
While parsing the body of an '*** Add File:' block, a non-blank line did not start with '+'. Add-file bodies require every content line to be prefixed with '+' (blank lines are tolerated as blank content). Any other leading character is rejected.
Source
Thrown at aider/coders/patch_coder.py:540
# Stop if we hit another action or end marker
if norm_line.startswith(
(
"*** End Patch",
"*** Update File:",
"*** Delete File:",
"*** Add File:",
)
):
break
# Expect lines to start with '+'
if not line.startswith("+"):
# Tolerate blank lines? Or require '+'? Reference implies '+' required.
if norm_line.strip() == "":
# Treat blank line as adding a blank line
added_lines.append("")
else:
raise DiffError(f"Invalid Add File line (missing '+'): {line}")
else:
added_lines.append(line[1:]) # Strip leading '+'
index += 1
action = PatchAction(type=ActionType.ADD, path="", new_content="\n".join(added_lines))
return action, index
def apply_edits(self, edits: List[PatchAction]):
"""
Applies the parsed PatchActions to the corresponding files.
"""
if not edits:
return
# Group edits by original path? Not strictly needed if processed sequentially.
# Edits are now List[Tuple[str, PatchAction]]View on GitHub (pinned to 5dc9490bb3)
Solutions
- Prefix every content line in the Add File block with '+'
- Regenerate — aider's retry loop typically gets the model to fix prefix mistakes
- Validate add-block lines with a linter/regex ('^($|\+|\*\*\*)') before applying
Example fix
// before *** Add File: a.txt hello // after *** Add File: a.txt +hello
Defensive patterns
Strategy: validation
Validate before calling
def add_body_prefixed(patch_text: str) -> bool:
in_add = False
for line in patch_text.splitlines():
if line.startswith("*** Add File: "):
in_add = True
elif line.startswith("*** "):
in_add = False
elif in_add and line and not line.startswith("+"):
return False
return True Try / catch
try:
edits = coder.get_edits(reply)
except DiffError as e:
if "Invalid Add File line (missing '+')" in str(e):
reply = auto_prefix_add_body(reply)
edits = coder.get_edits(reply)
else:
raise Prevention
- State in the prompt that Add File content lines must each start with '+'
- Reject patches whose add blocks contain raw (unprefixed) content
- Beware models mixing unified-diff '-'/' ' conventions into patch format
When it happens
Trigger: Model emits raw file content without '+' prefixes inside an Add File block; a '-' or ' ' diff-style line leaks in; a nested '***' header terminates the block and the stray line follows.
Common situations: Model mixes unified-diff habits into the patch format; long generated files where the model forgets prefixes partway; hand-written patches pasted from editors.
Related errors
- Delete File action missing path.
- Add File action missing path.
- Duplicate action for file: {path}
- Unknown or misplaced line while parsing patch: {line}
- Bad/missing filename. The filename must be alone on the line
AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15).
Data as JSON: /api/errors/d1369e0414ca4f0e.
Report an issue: GitHub.