oraios/serena · error · FileNotFoundError
File or directory {relative_path} does not exist in the proj
Error message
File or directory {relative_path} does not exist in the project. What it means
get_symbol_overview only accepts a path to an existing FILE (even though the underlying symbol retriever can handle directories, the tool deliberately forbids them). Before doing anything else it resolves the path against the project root and raises FileNotFoundError if nothing exists there.
Source
Thrown at src/serena/tools/symbol_tools.py:105
return "Depth 0 overview:\n" + self._to_json(compact_depth_0_result)
shortened_results = [make_depth_0_result, make_kind_counts]
return self._limit_length(result_json_str, max_answer_chars, shortened_result_factories=shortened_results)
def get_symbol_overview(self, relative_path: str, depth: int = 0) -> list[LanguageServerSymbol.OutputDict]:
"""
:param relative_path: relative path to a source file
:param depth: the depth up to which descendants shall be retrieved
:return: a list of symbol dictionaries representing the symbol overview of the file
"""
symbol_retriever = self.create_language_server_symbol_retriever()
# The symbol overview is capable of working with both files and directories,
# but we want to ensure that the user provides a file path.
file_path = os.path.join(self.project.project_root, relative_path)
if not os.path.exists(file_path):
raise FileNotFoundError(f"File or directory {relative_path} does not exist in the project.")
if os.path.isdir(file_path):
raise ValueError(f"Expected a file path, but got a directory path: {relative_path}. ")
if not symbol_retriever.can_analyze_file(relative_path):
raise ValueError(
f"Cannot extract symbols from file {relative_path}. Active language servers: {[l.value for l in self.agent.get_active_language_server_ids()]}"
)
symbols = symbol_retriever.get_symbol_overview(relative_path)[relative_path]
def child_inclusion_predicate(s: LanguageServerSymbol) -> bool:
return not s.is_low_level()
symbol_dicts = []
for symbol in symbols:
symbol_dicts.append(
symbol.to_dict(
name_path=False,
name=True,View on GitHub (pinned to 7fcbca7e62)
Solutions
- Verify the file exists relative to project root (os.path.exists(os.path.join(root, relative_path))) before calling
- Convert absolute paths to project-relative paths (pathlib.Path(abs).relative_to(project_root))
- List the project directory or use a file-listing tool to find the correct path
Example fix
// before get_symbol_overview.apply(relative_path='src/foo.py') # file actually at serena/src/foo.py // FileNotFoundError // after rel = str(Path(abs_path).relative_to(project_root)) assert (Path(project_root) / rel).exists() get_symbol_overview.apply(relative_path=rel)
Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
rel = str(Path(abs_path).resolve().relative_to(Path(project_root).resolve()))
if not (Path(project_root) / rel).exists():
raise FileNotFoundError(rel) Type guard
def path_exists_in_project(rel: str, root: str) -> bool:
return (Path(root) / rel).exists() Try / catch
try:
overview = symbol_tool.get_symbol_overview(relative_path=rel)
except FileNotFoundError:
rel = locate_file_with_file_tool(rel) # search project for correct path
overview = symbol_tool.get_symbol_overview(relative_path=rel) Prevention
- Always use project-relative paths, never absolute ones
- Verify file existence with a file-listing tool before symbol queries
- Watch for typos and case sensitivity in paths
When it happens
Trigger: Calling get_symbol_overview with a relative_path that does not exist under project root — typo'd path, wrong casing, path outside the configured project, or the file was deleted/moved after the path string was built.
Common situations: Agent hallucinates a file name; user passes an absolute path where a project-relative path is expected; project root changed so a previously valid relative path no longer resolves.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Error: Path does not exist: {project_root}
- Error: Path is not a directory: {project_root}
- Project root not found: {project_root}
- Relative path {start_path} not found.
- Expected a file path, but got a directory path: {relative_pa
AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29).
Data as JSON: /api/errors/61826d099b3ea0d3.
Report an issue: GitHub.