zed-industries/zed · error
is not a directory.
Error message
{} is not a directory. What it means
`list_directory` looks the path up in the worktree snapshot and requires the entry to be a directory (`entry.is_dir()`). A snapshot entry that is a regular file (or any non-directory) makes the tool bail with `{path} is not a directory.` The check happens after existence, so the path exists but has the wrong type.
Solutions
- Use the `read_file` tool for file paths — it is the counterpart that requires a non-directory.
- List the parent directory to discover the real children and pick a directory entry.
- If the path should be a directory, check whether it was replaced by a file on disk.
Example fix
// tool call before
{ "path": "src/main.rs" } // list_directory on a file -> error
// tool call after
{ "path": "src" } // list the parent directory
// or switch tools
read_file({ "path": "src/main.rs" }) Defensive patterns
Strategy: type-guard
Validate before calling
if let Some(entry) = worktree.read(cx).snapshot().entry_for_path(&project_path.path) {
if !entry.is_dir() {
// route to read_file instead of list_directory
}
} Type guard
fn is_listable_dir(snapshot: &WorktreeSnapshot, path: &ProjectPath) -> bool {
snapshot.entry_for_path(&path.path).is_some_and(|entry| entry.is_dir())
} Try / catch
match list_directory(path).await {
Err(e) if e.to_string().contains("is not a directory") => read_file(path).await,
rest => rest,
} Prevention
- Branch tool choice on `entry.is_dir()` before calling.
- Treat extension-less names (LICENSE, Dockerfile) as likely files when planning calls.
- When a generic 'explore path' intent is needed, check the entry kind first.
When it happens
Trigger: Calling `list_directory` on a file path — e.g. `list_directory("src/main.rs")` — or on a symlink whose snapshot entry is a file.
Common situations: The model confuses a file for a directory (common for extension-less files like `LICENSE`, `Makefile`, `Dockerfile`), or a path swapped from directory to file during a refactor.
Related errors
- Cannot list directory because its path matches the user's…
- Cannot list directory because its path matches the user's…
- Path not found
- auto_compact threshold of 0 is not valid
- Cannot read file because its path matches the global…
AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20).
Data as JSON: /api/errors/67a94f884a4aa967.
Report an issue: GitHub.
Appendix: source
Thrown at crates/agent/src/tools/list_directory_tool.rs:311
anyhow::bail!(
"Cannot list directory because its path matches the user's worktree `file_scan_exclusions` setting: {}",
input.path
);
}
if worktree_settings.is_path_private(&project_path.path) {
anyhow::bail!(
"Cannot list directory because its path matches the user's worktree `private_paths` setting: {}",
input.path
);
}
let worktree_snapshot = worktree.read(cx).snapshot();
let Some(entry) = worktree_snapshot.entry_for_path(&project_path.path) else {
anyhow::bail!("Path not found: {}", input.path);
};
if !entry.is_dir() {
anyhow::bail!("{} is not a directory.", input.path);
}
anyhow::Ok(())
}).map_err(|e| e.to_string())?;
if let Some(canonical_target) = &symlink_canonical_target {
let authorize = cx.update(|cx| {
authorize_symlink_access(
Self::NAME,
&input.path,
canonical_target,
&event_stream,
cx,
)
});
authorize.await.map_err(|e| e.to_string())?;
}
View on GitHub (pinned to f4178619ac)