{"record":{"id":"53e53fe83649289c","repo":"FoundationAgents/MetaGPT","slug":"file-file-path-not-found","errorCode":null,"errorMessage":"File {file_path} not found","messagePattern":"File (.+?) not found","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"metagpt/tools/libs/editor.py","lineNumber":1048,"sourceCode":"            res_list.append(f\"{file_path} (Line {line_num}): {line}\")\n        res_list.append(f'[End of matches for \"{search_term}\" in {dir_path}]')\n        return \"\\n\".join(res_list)\n\n    def search_file(self, search_term: str, file_path: Optional[str] = None) -> str:\n        \"\"\"Searches for search_term in file. If file is not provided, searches in the current open file.\n\n        Args:\n            search_term: str: The term to search for.\n            file_path: str | None: The path to the file to search.\n        \"\"\"\n        if file_path is None:\n            file_path = self.current_file\n        else:\n            file_path = self._try_fix_path(file_path)\n        if file_path is None:\n            raise FileNotFoundError(\"No file specified or open. Use the open_file function first.\")\n        if not file_path.is_file():\n            raise FileNotFoundError(f\"File {file_path} not found\")\n\n        matches = []\n        with file_path.open() as file:\n            for i, line in enumerate(file, 1):\n                if search_term in line:\n                    matches.append((i, line.strip()))\n        res_list = []\n        if matches:\n            res_list.append(f'[Found {len(matches)} matches for \"{search_term}\" in {file_path}]')\n            for match in matches:\n                res_list.append(f\"Line {match[0]}: {match[1]}\")\n            res_list.append(f'[End of matches for \"{search_term}\" in {file_path}]')\n        else:\n            res_list.append(f'[No matches found for \"{search_term}\" in {file_path}]')\n\n        extra = {\"type\": \"search\", \"symbol\": search_term, \"lines\": [i[0] - 1 for i in matches]} if matches else None\n        self.resource.report(file_path, \"path\", extra=extra)\n        return \"\\n\".join(res_list)","sourceCodeStart":1030,"sourceCodeEnd":1066,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/tools/libs/editor.py#L1030-L1066","documentation":"Raised by Editor.search_file when the resolved path exists in the string sense but is not a regular file (or the resolved value points nowhere). Before this check, file_path goes through _try_fix_path, which normalizes/repairs relative paths (e.g. adding a leading '/' or resolving against the workspace). If the fixed path still does not satisfy Path.is_file(), the search aborts.","triggerScenarios":"Passing file_path that does not exist on disk; passing a directory path instead of a file; passing a relative path that _try_fix_path resolves against the wrong root; passing a path with a typo or wrong extension.","commonSituations":"Agent hallucinates a plausible-looking path that was never created; file was renamed/deleted between planning and execution; cwd changed so a relative path no longer resolves; path points to a symlink whose target is gone.","solutions":["Verify the path with Path(file_path).is_file() before calling","Use editor.find_file(name) to locate the real path when unsure","Pass an absolute path to avoid _try_fix_path guessing on relative input"],"exampleFix":"# before\neditor.search_file(\"foo\", file_path=\"src/utils.py\")  # file actually at src/common/utils.py\n# after\nloc = editor.find_file(\"utils.py\")\n# parse a hit from loc, then:\neditor.search_file(\"foo\", file_path=\"/abs/repo/src/common/utils.py\")","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(file_path) if file_path else editor.current_file\nif p is None or not p.is_file():\n    raise SystemExit(f\"no such file: {p}\")","typeGuard":"def is_searchable_file(editor, file_path: str | None) -> bool:\n    p = Path(file_path) if file_path else editor.current_file\n    return p is not None and p.is_file()","tryCatchPattern":"try:\n    out = editor.search_file(term, str(p))\nexcept FileNotFoundError:\n    p = editor.find_file(p.name).splitlines()[1] if p else None  # recover via find_file","preventionTips":["Use absolute paths when calling editor tools from scripts","find_file first when the exact location is uncertain","Re-check existence right before use if files may be created/deleted during the run"],"tags":["editor","file-not-found","path"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}