zylon-ai/private-gpt · error · RuntimeError
Unable to view file
Error message
Unable to view file
What it means
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.
Source
Thrown at private_gpt/components/tools/builders/text_editor_tool_builder.py:93
description: str = TEXT_EDITOR_VIEW_TOOL_FN.metadata.description,
) -> ToolSpec:
async def view(
path: str,
view_range: list[int] | None = None,
) -> list[ResultContentBlockType]:
resolved_view_range: tuple[int, int] | None = None
if view_range is not None:
if len(view_range) != 2:
raise ValueError("view_range must contain exactly two integers")
resolved_view_range = (view_range[0], view_range[1])
session = await self._session(config)
result = await session.view(
path,
view_range=resolved_view_range,
)
if not result.success:
raise RuntimeError(result.error or "Unable to view file")
output = _truncated(
result.output, self._settings.code_execution.max_output_bytes
)
line_count = len(output.splitlines())
start_line = resolved_view_range[0] if resolved_view_range else 1
return [
TextEditorCodeExecutionViewResultBlock(
content=output,
num_lines=line_count,
start_line=start_line,
total_lines=line_count,
)
]
return ToolSpec.from_defaults(
name=name,
type=type,
runtime="server",View on GitHub (pinned to 4a030776a3)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
import os.path
# if you control the sandbox, verify the file exists before viewing
# (paths are inside the code-execution sandbox, not the host)
assert path and not path.endswith("/"), "path must be a file path" Try / catch
try:
blocks = await view(path=path, view_range=vr)
except RuntimeError as e:
detail = str(e) if str(e) != "Unable to view file" else "view failed without detail; check path and session"
logger.error("text_editor view failed: %s", detail)
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unable to replace text
- Unable to create file
- Path '{canonical_path}' does not match any session mount.
- Code execution failed: {message}
- Execution failed: {result.error or 'Unknown error'}
AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15).
Data as JSON: /api/errors/4183e44c4a35f60b.
Report an issue: GitHub.