{"record":{"id":"3bebf4503b99f42f","repo":"FoundationAgents/MetaGPT","slug":"str-file-or-path-not-exists","errorCode":null,"errorMessage":"\"{str(file_or_path)}\" not exists","messagePattern":"\"(.+?)\" not exists","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/tools/libs/index_repo.py","lineNumber":429,"sourceCode":"\n        This asynchronous function searches for the specified query in files\n        located at the given path or file.\n\n        Args:\n            query (str): The search term to look for in the files.\n            file_or_path (Union[str, Path]): The path to the file or directory\n                where the search should be conducted. This can be a string path\n                or a Path object.\n\n        Returns:\n            List[str]: A list of strings containing the paths of files that\n            contain the query results.\n\n        Raises:\n            ValueError: If the query string is empty.\n        \"\"\"\n        if not file_or_path or not Path(file_or_path).exists():\n            raise ValueError(f'\"{str(file_or_path)}\" not exists')\n        files = [file_or_path] if not Path(file_or_path).is_dir() else list_files(file_or_path)\n        clusters, roots = IndexRepo.find_index_repo_path(files)\n        futures = []\n        others = set()\n        for persist_path, filenames in clusters.items():\n            if persist_path == OTHER_TYPE:\n                others.update(filenames)\n                continue\n            root = roots[persist_path]\n            repo = IndexRepo(persist_path=persist_path, root_path=root)\n            futures.append(repo.search(query=query, filenames=list(filenames)))\n\n        for i in others:\n            futures.append(File.read_text_file(i))\n\n        futures_results = []\n        if futures:\n            futures_results = await asyncio.gather(*futures)","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/tools/libs/index_repo.py#L411-L447","documentation":"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.","triggerScenarios":"Awaiting IndexRepo.cross_repo_search(query=..., path=...) with path='', a typo'd path, or a path that was deleted; passing None-like/empty input.","commonSituations":"Agent-generated path hallucinations; relative path evaluated from the wrong cwd; file moved between planning and execution; stale path cached from an earlier session.","solutions":["Check `Path(p).exists()` before calling","Use an absolute path to remove cwd ambiguity","Locate the real file first with Editor.find_file if the path is uncertain"],"exampleFix":"# before\nawait IndexRepo.cross_repo_search(query=q, path=\"docs/handbook.md\")  # typo\n# after\nfrom pathlib import Path\np = next(Path(\".\").rglob(\"handbook*.md\"), None)\nif p:\n    await IndexRepo.cross_repo_search(query=q, path=p)","handlingStrategy":"validation","validationCode":"from pathlib import Path\nif not file_or_path or not Path(file_or_path).exists():\n    raise SystemExit(f\"bad path: {file_or_path!r}\")","typeGuard":"def is_existing_target(p) -> bool:\n    from pathlib import Path\n    return bool(p) and Path(p).exists()","tryCatchPattern":"try:\n    res = await IndexRepo.cross_repo_search(query=q, path=p)\nexcept ValueError as e:\n    if \"not exists\" in str(e):\n        p = next(Path(\".\").rglob(Path(p).name), None)  # relocate and retry once","preventionTips":["Validate existence at the boundary where paths enter the system","Prefer absolute paths in persisted plans","For agent-generated paths, confirm with a filesystem check before RAG calls"],"tags":["rag","path","validation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}