Aider-AI/aider · error · ValueError

Error parsing patch content: {e}

Error message

Error parsing patch content: {e}

What it means

The outer wrapper in PatchCoder.get_edits: any DiffError raised while parsing the patch body (invalid '***' line, bad line prefix, empty section, missing path, conflicting actions, missing file content, etc.) is re-raised as ValueError('Error parsing patch content: ...'). This normalization matches other coders' error handling so the shared retry loop can feed the message back to the LLM.

Source

Thrown at aider/coders/patch_coder.py:285

                    )
                current_files[rel_path] = file_content
            except FileNotFoundError:
                raise DiffError(f"File referenced in patch not found: {rel_path}")
            except IOError as e:
                raise DiffError(f"Error reading file {rel_path}: {e}")

        try:
            # Parse the patch text using adapted logic
            patch_obj = self._parse_patch_text(lines, start_index, current_files)
            # Convert Patch object actions dict to a list of tuples (path, action)
            # for compatibility with the base Coder's prepare_to_edit method.
            results = []
            for path, action in patch_obj.actions.items():
                results.append((path, action))
            return results
        except DiffError as e:
            # Raise as ValueError for consistency with other coders' error handling
            raise ValueError(f"Error parsing patch content: {e}")
        except Exception as e:
            # Catch unexpected errors during parsing
            raise ValueError(f"Unexpected error parsing patch: {e}")

    def _parse_patch_text(
        self, lines: List[str], start_index: int, current_files: Dict[str, str]
    ) -> Patch:
        """
        Parses patch content lines into a Patch object.
        Adapted from the Parser class in apply_patch.py.
        """
        patch = Patch()
        index = start_index
        fuzz_accumulator = 0

        while index < len(lines):
            line = lines[index]
            norm_line = _norm(line)

View on GitHub (pinned to 5dc9490bb3)

Solutions

  1. Read the suffix after 'Error parsing patch content:' — it is the specific DiffError (e.g. 'Invalid line prefix...', 'Update File action missing path.') and fix that.
  2. Send the message back to the model; PatchCoder's design expects the ValueError to drive a retry with a corrected patch.
  3. If the model persistently fails apply_patch grammar, switch edit format (--edit-format diff or udiff).
  4. Reproduce in isolation by calling PatchCoder.get_edits() on the saved reply text to iterate quickly.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    edits = coder.get_edits(reply)
except ValueError as e:
    msg = str(e)
    if msg.startswith("Error parsing patch content:"):
        underlying = msg[len("Error parsing patch content:"):].strip()
        reply = ask_model_to_fix_patch(underlying)   # the intended retry loop
        edits = coder.get_edits(reply)
    else:
        raise

Prevention

When it happens

Trigger: Any structural defect in an apply_patch-grammar reply: the underlying DiffErrors are errors 7-9 and 15-19 plus context-lookup failures during _parse_patch_text. It surfaces whenever the model's patch violates the grammar defined in _parse_patch_text.

Common situations: Generic catch-all seen in aider logs whenever the 'patch' (apply_patch) edit format output is malformed; frequent right after model/provider changes that alter output formatting habits.

Related errors


AI-assisted analysis of Aider-AI/aider@5dc9490bb3 (2026-08-15). Data as JSON: /api/errors/8ae6b3d40ded1f6e. Report an issue: GitHub.