{"record":{"id":"10b99f8db8ff1da5","repo":"FoundationAgents/OpenManus","slug":"failed-to-write-to-path-str-e","errorCode":null,"errorMessage":"Failed to write to {path}: {str(e)}","messagePattern":"Failed to write to (.+?): (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"app/tool/file_operators.py","lineNumber":59,"sourceCode":"\nclass LocalFileOperator(FileOperator):\n    \"\"\"File operations implementation for local filesystem.\"\"\"\n\n    encoding: str = \"utf-8\"\n\n    async def read_file(self, path: PathLike) -> str:\n        \"\"\"Read content from a local file.\"\"\"\n        try:\n            return Path(path).read_text(encoding=self.encoding)\n        except Exception as e:\n            raise ToolError(f\"Failed to read {path}: {str(e)}\") from None\n\n    async def write_file(self, path: PathLike, content: str) -> None:\n        \"\"\"Write content to a local file.\"\"\"\n        try:\n            Path(path).write_text(content, encoding=self.encoding)\n        except Exception as e:\n            raise ToolError(f\"Failed to write to {path}: {str(e)}\") from None\n\n    async def is_directory(self, path: PathLike) -> bool:\n        \"\"\"Check if path points to a directory.\"\"\"\n        return Path(path).is_dir()\n\n    async def exists(self, path: PathLike) -> bool:\n        \"\"\"Check if path exists.\"\"\"\n        return Path(path).exists()\n\n    async def run_command(\n        self, cmd: str, timeout: Optional[float] = 120.0\n    ) -> Tuple[int, str, str]:\n        \"\"\"Run a shell command locally.\"\"\"\n        process = await asyncio.create_subprocess_shell(\n            cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE\n        )\n\n        try:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/tool/file_operators.py#L41-L77","documentation":"LocalFileOperator.write_file wraps Path.write_text failures in a ToolError. The filesystem cause in '{e}' is usually PermissionError (target dir not writable), FileNotFoundError (parent directory does not exist — write_text does not create parents), or OSError errno 28 (no space left on device).","triggerScenarios":"Writing to /workspace/out/report.md when 'out/' was never created; writing into a directory owned by another user or a read-only bind mount; disk/quota exhausted after large generated artifacts.","commonSituations":"Agent writes to nested output paths without creating them first; container workspace mounted read-only; long sandbox sessions filling a small tmpfs or disk quota.","solutions":["Create parent directories before writing: Path(path).parent.mkdir(parents=True, exist_ok=True).","Check writability early: attempt a probe write (or os.access) into the target directory at session start.","For ENOSPC, clean or enlarge the volume and have the pipeline emit smaller artifacts; check 'df' inside the sandbox.","Catch ToolError at the caller and surface '{e}' — it distinguishes permission vs missing-parent vs disk-full."],"exampleFix":"# before\nawait file_op.write_file(\"/workspace/out/report.md\", content)  # parent missing -> ToolError\n\n# after\nfrom pathlib import Path\nPath(\"/workspace/out\").mkdir(parents=True, exist_ok=True)\nawait file_op.write_file(\"/workspace/out/report.md\", content)","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(path)\np.parent.mkdir(parents=True, exist_ok=True)\nif not os.access(p.parent, os.W_OK):\n    raise ToolError(f'{p.parent} is not writable')","typeGuard":null,"tryCatchPattern":"try:\n    await file_op.write_file(path, content)\nexcept ToolError as e:\n    msg = str(e)\n    if 'No such file or directory' in msg:\n        Path(path).parent.mkdir(parents=True, exist_ok=True)\n        await file_op.write_file(path, content)\n    elif 'Permission' in msg or 'Read-only' in msg:\n        path = fallback_path_in_writable_dir  # pick a writable location\n        await file_op.write_file(path, content)\n    else:\n        raise  # e.g. No space left on device — needs cleanup, not retry","preventionTips":["mkdir -p the parent before every nested write.","Probe workspace writability at session start.","Watch disk usage in long sandbox sessions (ENOSPC surfaces here)."],"tags":["filesystem","file-write","permissions","disk-full"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}