{"record":{"id":"4183e44c4a35f60b","repo":"zylon-ai/private-gpt","slug":"unable-to-view-file","errorCode":null,"errorMessage":"Unable to view file","messagePattern":"Unable to view file","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/tools/builders/text_editor_tool_builder.py","lineNumber":93,"sourceCode":"        description: str = TEXT_EDITOR_VIEW_TOOL_FN.metadata.description,\n    ) -> ToolSpec:\n        async def view(\n            path: str,\n            view_range: list[int] | None = None,\n        ) -> list[ResultContentBlockType]:\n            resolved_view_range: tuple[int, int] | None = None\n            if view_range is not None:\n                if len(view_range) != 2:\n                    raise ValueError(\"view_range must contain exactly two integers\")\n                resolved_view_range = (view_range[0], view_range[1])\n\n            session = await self._session(config)\n            result = await session.view(\n                path,\n                view_range=resolved_view_range,\n            )\n            if not result.success:\n                raise RuntimeError(result.error or \"Unable to view file\")\n            output = _truncated(\n                result.output, self._settings.code_execution.max_output_bytes\n            )\n            line_count = len(output.splitlines())\n            start_line = resolved_view_range[0] if resolved_view_range else 1\n            return [\n                TextEditorCodeExecutionViewResultBlock(\n                    content=output,\n                    num_lines=line_count,\n                    start_line=start_line,\n                    total_lines=line_count,\n                )\n            ]\n\n        return ToolSpec.from_defaults(\n            name=name,\n            type=type,\n            runtime=\"server\",","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tools/builders/text_editor_tool_builder.py#L75-L111","documentation":"RuntimeError from the view tool: the code execution session's view() call completed but returned a result with success=False. The message is result.error when the session supplied one, otherwise the generic 'Unable to view file' fallback; the real cause (missing file, permissions, invalid range) is in result.error.","triggerScenarios":"session.view(path, view_range) fails: path does not exist in the sandbox, file unreadable, or the requested line range exceeds the file; result.success is False so the closure raises RuntimeError.","commonSituations":"Agent assumes a file exists from a previous turn but the sandbox session was restarted/expired (session_ttl_seconds); wrong relative path vs sandbox working directory; viewing a binary or huge file the provider refuses to read.","solutions":["Inspect the exception message: if it is just 'Unable to view file', log result.error from a wrapper to get the session's detailed reason.","Verify the path exists in the sandbox (list the directory or run ls via the bash tool) and use an absolute path.","If the session expired (TTL), recreate the session/config and retry the view.","Check that view_range, when given, lies within the file's line count."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import os.path\n# if you control the sandbox, verify the file exists before viewing\n# (paths are inside the code-execution sandbox, not the host)\nassert path and not path.endswith(\"/\"), \"path must be a file path\"","typeGuard":null,"tryCatchPattern":"try:\n    blocks = await view(path=path, view_range=vr)\nexcept RuntimeError as e:\n    detail = str(e) if str(e) != \"Unable to view file\" else \"view failed without detail; check path and session\"\n    logger.error(\"text_editor view failed: %s\", detail)\n    raise","preventionTips":["View a file before editing it to confirm the path and content in the current session.","Use absolute paths relative to the sandbox workspace root.","Recreate the session after TTL expiry instead of reusing stale configs."],"tags":["text-editor","code-execution","file-io","sandbox"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}