{"record":{"id":"b884a20e72a00494","repo":"FoundationAgents/MetaGPT","slug":"file-path-not-found-b884a2","errorCode":null,"errorMessage":"File {path} not found","messagePattern":"File (.+?) not found","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"metagpt/tools/libs/editor.py","lineNumber":297,"sourceCode":"    def open_file(\n        self, path: Union[Path, str], line_number: Optional[int] = 1, context_lines: Optional[int] = None\n    ) -> str:\n        \"\"\"Opens the file at the given path in the editor. If line_number is provided, the window will be moved to include that line.\n        It only shows the first 100 lines by default! Max `context_lines` supported is 2000, use `scroll up/down`\n        to view the file if you want to see more.\n\n        Args:\n            path: str: The path to the file to open, preferred absolute path.\n            line_number: int | None = 1: The line number to move to. Defaults to 1.\n            context_lines: int | None = 100: Only shows this number of lines in the context window (usually from line 1), with line_number as the center (if possible). Defaults to 100.\n        \"\"\"\n        if context_lines is None:\n            context_lines = self.window\n\n        path = self._try_fix_path(path)\n\n        if not path.is_file():\n            raise FileNotFoundError(f\"File {path} not found\")\n\n        self.current_file = path\n        with path.open() as file:\n            total_lines = max(1, sum(1 for _ in file))\n\n        if not isinstance(line_number, int) or line_number < 1 or line_number > total_lines:\n            raise ValueError(f\"Line number must be between 1 and {total_lines}\")\n        self.current_line = line_number\n\n        # Override WINDOW with context_lines\n        if context_lines is None or context_lines < 1:\n            context_lines = self.window\n\n        output = self._cur_file_header(path, total_lines)\n        output += self._print_window(path, self.current_line, self._clamp(context_lines, 1, 2000))\n        self.resource.report(path, \"path\")\n        return output\n","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/tools/libs/editor.py#L279-L315","documentation":"Raised by Editor.open_file after path normalization (_try_fix_path) when the resolved path does not point to an existing regular file. The editor deliberately fails fast instead of creating the file: open_file is strictly for existing files, while create_file makes new ones.","triggerScenarios":"editor.open_file('src/app.py') where the file does not exist; passing a directory path; passing a relative path that _try_fix_path resolves against the wrong base directory; typos or wrong-case filenames on case-sensitive filesystems.","commonSituations":"Relative paths resolved from an unexpected CWD; agent-generated paths that guess at filenames; files not yet created because a previous create/write step failed; symlink targets deleted.","solutions":["Verify the path exists with Path(p).is_file() before calling open_file","If the file is new, use editor.create_file(path) instead of open_file","Pass an absolute path, or check what base directory _try_fix_path resolves relative paths against"],"exampleFix":"// before\neditor.open_file('src/utils/helper.py')  # FileNotFoundError\n\n// after\np = Path('src/utils/helper.py')\nif p.is_file():\n    editor.open_file(str(p))\nelse:\n    editor.create_file(str(p))","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(path)\nif not p.is_file():\n    raise SystemExit(f'missing file: {p.resolve()}')\neditor.open_file(str(p))","typeGuard":"def is_openable_file(p: str) -> bool:\n    return Path(p).is_file()","tryCatchPattern":"try:\n    editor.open_file(path)\nexcept FileNotFoundError:\n    editor.create_file(path)  # only if creating is intended","preventionTips":["Prefer absolute paths so resolution does not depend on CWD","Use create_file for new files and open_file for existing ones","Validate paths at the boundary where LLM/user input enters your pipeline"],"tags":["editor","filesystem","path","metagpt"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}