FoundationAgents/MetaGPT · error · ValueError

"{str(file_or_path)}" not exists

Error message

"{str(file_or_path)}" not exists

What it means

ValueError from IndexRepo.cross_repo_search: the file_or_path argument is empty or its path does not exist on disk. The class-level entry point first validates the target before clustering files into per-root index repos, so a bad path fails fast.

Source

Thrown at metagpt/tools/libs/index_repo.py:429

        This asynchronous function searches for the specified query in files
        located at the given path or file.

        Args:
            query (str): The search term to look for in the files.
            file_or_path (Union[str, Path]): The path to the file or directory
                where the search should be conducted. This can be a string path
                or a Path object.

        Returns:
            List[str]: A list of strings containing the paths of files that
            contain the query results.

        Raises:
            ValueError: If the query string is empty.
        """
        if not file_or_path or not Path(file_or_path).exists():
            raise ValueError(f'"{str(file_or_path)}" not exists')
        files = [file_or_path] if not Path(file_or_path).is_dir() else list_files(file_or_path)
        clusters, roots = IndexRepo.find_index_repo_path(files)
        futures = []
        others = set()
        for persist_path, filenames in clusters.items():
            if persist_path == OTHER_TYPE:
                others.update(filenames)
                continue
            root = roots[persist_path]
            repo = IndexRepo(persist_path=persist_path, root_path=root)
            futures.append(repo.search(query=query, filenames=list(filenames)))

        for i in others:
            futures.append(File.read_text_file(i))

        futures_results = []
        if futures:
            futures_results = await asyncio.gather(*futures)

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Check `Path(p).exists()` before calling
  2. Use an absolute path to remove cwd ambiguity
  3. Locate the real file first with Editor.find_file if the path is uncertain

Example fix

# before
await IndexRepo.cross_repo_search(query=q, path="docs/handbook.md")  # typo
# after
from pathlib import Path
p = next(Path(".").rglob("handbook*.md"), None)
if p:
    await IndexRepo.cross_repo_search(query=q, path=p)
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path
if not file_or_path or not Path(file_or_path).exists():
    raise SystemExit(f"bad path: {file_or_path!r}")

Type guard

def is_existing_target(p) -> bool:
    from pathlib import Path
    return bool(p) and Path(p).exists()

Try / catch

try:
    res = await IndexRepo.cross_repo_search(query=q, path=p)
except ValueError as e:
    if "not exists" in str(e):
        p = next(Path(".").rglob(Path(p).name), None)  # relocate and retry once

Prevention

When it happens

Trigger: Awaiting IndexRepo.cross_repo_search(query=..., path=...) with path='', a typo'd path, or a path that was deleted; passing None-like/empty input.

Common situations: Agent-generated path hallucinations; relative path evaluated from the wrong cwd; file moved between planning and execution; stale path cached from an earlier session.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/3bebf4503b99f42f. Report an issue: GitHub.