{"record":{"id":"e1818096f1e71504","repo":"FoundationAgents/OpenManus","slug":"failed-to-read-file-e","errorCode":null,"errorMessage":"Failed to read file: {e}","messagePattern":"Failed to read file: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"app/sandbox/core/sandbox.py","lineNumber":196,"sourceCode":"        \"\"\"\n        if not self.container:\n            raise RuntimeError(\"Sandbox not initialized\")\n\n        try:\n            # Get file archive\n            resolved_path = self._safe_resolve_path(path)\n            tar_stream, _ = await asyncio.to_thread(\n                self.container.get_archive, resolved_path\n            )\n\n            # Read file content from tar stream\n            content = await self._read_from_tar(tar_stream)\n            return content.decode(\"utf-8\")\n\n        except NotFound:\n            raise FileNotFoundError(f\"File not found: {path}\")\n        except Exception as e:\n            raise RuntimeError(f\"Failed to read file: {e}\")\n\n    async def write_file(self, path: str, content: str) -> None:\n        \"\"\"Writes content to a file in the container.\n\n        Args:\n            path: Target path.\n            content: File content.\n\n        Raises:\n            RuntimeError: If write operation fails.\n        \"\"\"\n        if not self.container:\n            raise RuntimeError(\"Sandbox not initialized\")\n\n        try:\n            resolved_path = self._safe_resolve_path(path)\n            parent_dir = os.path.dirname(resolved_path)\n","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/sandbox/core/sandbox.py#L178-L214","documentation":"Catch-all RuntimeError from DockerSandbox.read_file (app/sandbox/core/sandbox.py:196): the archive was fetched but processing failed — decoding the tar stream, reading members, or content.decode(\"utf-8\"). NotFound is handled separately (error 28); everything else (UnicodeDecodeError, tar errors, Docker API errors mid-stream) lands here with the cause in {e}.","triggerScenarios":"Reading a binary file (PNG, pickle, zip) — content.decode(\"utf-8\") raises UnicodeDecodeError; tar stream truncated mid-transfer; get_archive returning a directory when a file was expected; Docker API connection reset while streaming chunks.","commonSituations":"Agent writes a plot/screenshot then read_file is used on it; reading large files that hit daemon stream limits; reading a path that is a directory (archive has multiple members and the reader takes raw bytes).","solutions":["Check {e}: UnicodeDecodeError means binary content — use copy_from instead of read_file for non-text files.","For directories or large files, use copy_from(src, dst) which handles tar extraction properly.","Retry once on connection-reset style errors (transient daemon/stream issues).","Confirm the path points at a regular file: run_command(f\"test -f {path}\")."],"exampleFix":"# before\ntext = await sandbox.read_file(\"chart.png\")  # UnicodeDecodeError -> RuntimeError\n\n# after\nawait sandbox.copy_from(\"chart.png\", \"/tmp/host/chart.png\")  # binary-safe path","handlingStrategy":"try-catch","validationCode":"is_text = (await sandbox.run_command(f\"file -b {shlex.quote(path)}\")).strip().startswith(\"ASCII\")","typeGuard":null,"tryCatchPattern":"try:\n    return await sandbox.read_file(path)\nexcept RuntimeError as e:\n    if \"UnicodeDecodeError\" in str(e.__cause__ or e):\n        tmp = tempfile.mkdtemp()\n        await sandbox.copy_from(path, tmp)\n        return open(os.path.join(tmp, os.path.basename(path)), \"rb\").read()  # bytes path\n    raise","preventionTips":["Use read_file only for text; use copy_from for binary","Verify the path is a regular file with test -f","Retry once on transient stream errors"],"tags":["sandbox","file-io","encoding","tar","wrapper-exception"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}