{"record":{"id":"8ae6b3d40ded1f6e","repo":"Aider-AI/aider","slug":"error-parsing-patch-content-e","errorCode":null,"errorMessage":"Error parsing patch content: {e}","messagePattern":"Error parsing patch content: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aider/coders/patch_coder.py","lineNumber":285,"sourceCode":"                    )\n                current_files[rel_path] = file_content\n            except FileNotFoundError:\n                raise DiffError(f\"File referenced in patch not found: {rel_path}\")\n            except IOError as e:\n                raise DiffError(f\"Error reading file {rel_path}: {e}\")\n\n        try:\n            # Parse the patch text using adapted logic\n            patch_obj = self._parse_patch_text(lines, start_index, current_files)\n            # Convert Patch object actions dict to a list of tuples (path, action)\n            # for compatibility with the base Coder's prepare_to_edit method.\n            results = []\n            for path, action in patch_obj.actions.items():\n                results.append((path, action))\n            return results\n        except DiffError as e:\n            # Raise as ValueError for consistency with other coders' error handling\n            raise ValueError(f\"Error parsing patch content: {e}\")\n        except Exception as e:\n            # Catch unexpected errors during parsing\n            raise ValueError(f\"Unexpected error parsing patch: {e}\")\n\n    def _parse_patch_text(\n        self, lines: List[str], start_index: int, current_files: Dict[str, str]\n    ) -> Patch:\n        \"\"\"\n        Parses patch content lines into a Patch object.\n        Adapted from the Parser class in apply_patch.py.\n        \"\"\"\n        patch = Patch()\n        index = start_index\n        fuzz_accumulator = 0\n\n        while index < len(lines):\n            line = lines[index]\n            norm_line = _norm(line)","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/coders/patch_coder.py#L267-L303","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Send the message back to the model; PatchCoder's design expects the ValueError to drive a retry with a corrected patch.","If the model persistently fails apply_patch grammar, switch edit format (--edit-format diff or udiff).","Reproduce in isolation by calling PatchCoder.get_edits() on the saved reply text to iterate quickly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    edits = coder.get_edits(reply)\nexcept ValueError as e:\n    msg = str(e)\n    if msg.startswith(\"Error parsing patch content:\"):\n        underlying = msg[len(\"Error parsing patch content:\"):].strip()\n        reply = ask_model_to_fix_patch(underlying)   # the intended retry loop\n        edits = coder.get_edits(reply)\n    else:\n        raise","preventionTips":["Route on the 'Error parsing patch content:' prefix, then handle the specific DiffError suffix (bad prefix, stray '***', empty section, missing path...).","Keep the model's patch examples in the system prompt grammatically perfect — it imitates them.","Log reply + error pairs; recurring shapes make good regression tests."],"tags":["aider","patch-format","parsing","error-context"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}