← Back to PRs

#12231: fix(read): add directory check before reading file

by higginsvott open 2026-02-09 01:39 View on GitHub →
agents stale
## Summary Adds a pre-flight check to detect when a directory path is passed to the Read tool, providing a clear error message instead of the cryptic EISDIR error from Node.js. ## Problem When a directory path is accidentally passed to the Read tool (e.g., `memory/projects` instead of `memory/projects/file.md`), the user gets a confusing error: ``` EISDIR: illegal operation on a directory, read ``` ## Solution Added a `fs.stat()` check before attempting to read the file. If the path is a directory, throw a user-friendly error: ``` Cannot read 'memory/projects': path is a directory, not a file. Use a specific file path (e.g., memory/projects/filename.md) ``` ## Testing - Existing tests pass - Manually verified the error message improvement ## Related Discovered while debugging cron job errors in OpenClaw gateway. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds a pre-flight directory check to the Read tool wrapper so directory paths produce a clearer error message, and it tweaks CDP screenshot capture so `captureBeyondViewport` is tied to `fullPage`. The directory check is implemented in `src/agents/pi-tools.read.ts` inside `createOpenClawReadTool`, which is used both for sandboxed and non-sandboxed read tool creation. <h3>Confidence Score: 2/5</h3> - This PR should not be merged as-is due to a sandbox escape/probing regression in the read tool wrapper. - The added `fs.stat()` preflight check runs inside `createOpenClawReadTool` and can execute before sandbox path enforcement, enabling host path probing in sandboxed sessions. There is also a new unused import which may break CI depending on lint/tsc settings. The CDP change looks isolated and low risk. - src/agents/pi-tools.read.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs