# agent: Return clear error when read_file tool path is a directory \(\#54303\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/3afcafe3fc0eb6d2aec28ec8d7900a455f873cc3)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 3afcafe3fc0eb6d2aec28ec8d7900a455f873cc3

Requested commit: 3afcafe3fc0eb6d2aec28ec8d7900a455f873cc3

Commit: 3afcafe3fc0eb6d2aec28ec8d7900a455f873cc3

Tree: 34f9208adc3e6fda61b13deaebbe49ff5e404da6

Author: Prohect

Committer: GitHub

## Message

```
agent: Return clear error when read_file tool path is a directory (#54303)

Fixes #54244

When the `read_file` tool is called with a path that points to a
directory instead of a file, it now returns a clear, actionable error
message telling the agent to use `list_directory` instead.

Previously the tool would fail with an unhelpful generic error. Now it
explicitly checks whether the path is a directory before attempting to
read it.

A test covering this case is also included.

Release Notes:

- Fixed `read_file` tool returning an unhelpful error when given a
directory path; it now suggests using `list_directory` instead.

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
```

## Parents

- [65107c90b10d2719b4739277ed5c06612d3180a4](https://git.cafe/gitcafe/zed/commit/65107c90b10d2719b4739277ed5c06612d3180a4?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/3afcafe3fc0eb6d2aec28ec8d7900a455f873cc3?format=markdown)
