{"record":{"id":"95c652d62ead0e51","repo":"Aider-AI/aider","slug":"error-applying-action-action-type-to-action-p","errorCode":null,"errorMessage":"Error applying action '{action.type}' to {action.path}: {e}","messagePattern":"Error applying action '(.+?)' to (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aider/coders/patch_coder.py","lineNumber":635,"sourceCode":"                            )\n                    else:\n                        self.io.tool_output(f\"Updating {action.path}\")\n\n                    # Ensure parent directory exists for target\n                    target_path_obj.parent.mkdir(parents=True, exist_ok=True)\n                    self.io.write_text(target_full_path, new_content)\n\n                    # Remove original file *after* successful write to new location if moved\n                    if action.move_path and full_path != target_full_path:\n                        path_obj.unlink()\n\n                else:\n                    # Should not happen\n                    raise DiffError(f\"Unknown action type encountered: {action.type}\")\n\n            except (DiffError, FileNotFoundError, IOError, OSError) as e:\n                # Raise a ValueError to signal failure, consistent with other coders.\n                raise ValueError(f\"Error applying action '{action.type}' to {action.path}: {e}\")\n            except Exception as e:\n                # Catch unexpected errors during application\n                raise ValueError(\n                    f\"Unexpected error applying action '{action.type}' to {action.path}: {e}\"\n                )\n\n    def _apply_update(self, text: str, action: PatchAction, path: str) -> str:\n        \"\"\"\n        Applies UPDATE chunks to the given text content.\n        Adapted from _get_updated_file in apply_patch.py.\n        \"\"\"\n        if action.type is not ActionType.UPDATE:\n            # Should not be called otherwise, but check for safety\n            raise DiffError(\"_apply_update called with non-update action\")\n\n        orig_lines = text.splitlines()  # Use splitlines to handle endings consistently\n        dest_lines: List[str] = []\n        current_orig_line_idx = 0  # Tracks index in orig_lines processed so far","sourceCodeStart":617,"sourceCodeEnd":653,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/coders/patch_coder.py#L617-L653","documentation":"Wrapper: apply_edits catches DiffError, FileNotFoundError, IOError, and OSError raised while applying one action and re-raises as ValueError with the action type, path, and original message. The ValueError convention matches other coders' failure signaling, so callers only handle one exception type.","triggerScenarios":"Any per-action failure (add-exists, update-missing, chunk mismatch, IO error) inside apply_edits; the message embeds the underlying DiffError text such as 'UPDATE Error: File does not exist: x.py'.","commonSituations":"Callers of coder.apply_edits (GUI, tests, automation) catching ValueError to detect failed patch application; partial application — earlier actions in the loop may already have been written.","solutions":["Parse the embedded cause (action type + path) from the message and fix that specific condition, then re-apply","Verify filesystem state afterward — actions before the failing one were already applied","Restore/checkpoint the repo (git status) before retrying to avoid double-application"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    coder.apply_edits(edits)\nexcept ValueError as e:\n    # message shape: \"Error applying action '<TYPE>' to <path>: <cause>\"\n    import re\n    m = re.match(r\"Error applying action '(\\w+)' to (.*): (.*)\", str(e), re.S)\n    if m:\n        action_type, path, cause = m.groups()\n        log.warning(\"apply failed for %s on %s: %s\", action_type, path, cause)\n    raise","preventionTips":["Treat apply as transactional-ish: snapshot git state before applying multi-action patches","Check filesystem preconditions (existence, readability) per action before apply","Log the wrapped cause — it always embeds the real DiffError text"],"tags":["aider","patch","apply","error-wrapping"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}