{"record":{"id":"fdd126bed328a576","repo":"Aider-AI/aider","slug":"could-not-read-file-for-update-action-path","errorCode":null,"errorMessage":"Could not read file for UPDATE: {action.path}","messagePattern":"Could not read file for UPDATE: (.+?)","errorType":"exception","errorClass":"DiffError","httpStatus":null,"severity":"error","filePath":"aider/coders/patch_coder.py","lineNumber":598,"sourceCode":"                    self.io.write_text(full_path, content_to_write)\n\n                elif action.type == ActionType.DELETE:\n                    self.io.tool_output(f\"Deleting {action.path}\")\n                    if not path_obj.exists():\n                        self.io.tool_warning(\n                            f\"DELETE Warning: File not found, skipping: {action.path}\"\n                        )\n                    else:\n                        path_obj.unlink()\n\n                elif action.type == ActionType.UPDATE:\n                    if not path_obj.exists():\n                        raise DiffError(f\"UPDATE Error: File does not exist: {action.path}\")\n\n                    current_content = self.io.read_text(full_path)\n                    if current_content is None:\n                        # Should have been caught during parsing if file was needed\n                        raise DiffError(f\"Could not read file for UPDATE: {action.path}\")\n\n                    # Apply the update logic using the parsed chunks\n                    new_content = self._apply_update(current_content, action, action.path)\n\n                    target_full_path = (\n                        self.abs_root_path(action.move_path) if action.move_path else full_path\n                    )\n                    target_path_obj = pathlib.Path(target_full_path)\n\n                    if action.move_path:\n                        self.io.tool_output(\n                            f\"Updating and moving {action.path} to {action.move_path}\"\n                        )\n                        # Check if target exists before overwriting/moving\n                        if target_path_obj.exists() and full_path != target_full_path:\n                            self.io.tool_warning(\n                                \"UPDATE Warning: Target file for move already exists, overwriting:\"\n                                f\" {action.move_path}\"","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/coders/patch_coder.py#L580-L616","documentation":"Raised when an UPDATE target exists but io.read_text(full_path) returns None — the IO layer failed to read the file (encoding failure, permission issue, or unreadable path). Exists-but-unreadable is treated as an apply-time error rather than silently skipping.","triggerScenarios":"Binary or non-declared-encoding files (read_text with strict encoding returns None); permission-denied on the file; file deleted between the exists() check and the read (TOCTOU).","commonSituations":"Patching a file with an encoding mismatch (e.g. latin-1 content read as utf-8); read-only mounts or sandboxed filesystems; races with external processes removing files.","solutions":["Verify the file's encoding and aider's --encoding setting match","Check read permissions on the file and parent directories","Re-check the file still exists immediately before applying to rule out a race"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def update_targets_readable(root, actions) -> list[str]:\n    bad = []\n    for a in actions:\n        if a.type.name == \"UPDATE\":\n            p = os.path.join(root, a.path)\n            try:\n                with open(p, \"r\", encoding=\"utf-8\") as f:\n                    f.read()\n            except (OSError, UnicodeDecodeError):\n                bad.append(a.path)\n    return bad","typeGuard":null,"tryCatchPattern":"try:\n    coder.apply_edits(edits)\nexcept ValueError as e:\n    if \"Could not read file for UPDATE\" in str(e):\n        path = str(e).split(\"UPDATE: \", 1)[-1].strip()\n        raise RuntimeError(f\"unreadable file {path}: check encoding/permissions\")\n    raise","preventionTips":["Match aider's --encoding to the file's real encoding","Avoid pointing the coder at binary files","Confirm read permissions in sandboxed/containerized runs"],"tags":["aider","patch","update","io","encoding"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}