mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 18:16:10 +00:00
Better error message on FileNotFoundError (#480)
- Check if directory exists before calling validate_relative_path
- Return structured JSON error with project_root context when directory not found
- Helps LLMs understand the current working directory context in MCP
Similar to fix in commit 8464f25 for CreateTextFileTool
This commit is contained in:
1 parent
de173ce078
commit
bcc4a9e5d9
1 file changed
+9
@@ -100,6 +100,15 @@ class ListDirTool(Tool):
|
||||
required for the task.
|
||||
:return: a JSON object with the names of directories and files within the given directory
|
||||
"""
|
||||
# Check if the directory exists before validation
|
||||
if not self.project.relative_path_exists(relative_path):
|
||||
error_info = {
|
||||
"error": f"Directory not found: {relative_path}",
|
||||
"project_root": self.get_project_root(),
|
||||
"hint": "Check if the path is correct relative to the project root",
|
||||
}
|
||||
return json.dumps(error_info)
|
||||
|
||||
self.project.validate_relative_path(relative_path)
|
||||
|
||||
dirs, files = scan_directory(
|
||||
|
||||
Reference in new issue
Block a user