{"record":{"id":"8de0cb4051db71d9","repo":"FoundationAgents/MetaGPT","slug":"file-path-not-found","errorCode":null,"errorMessage":"File {path} not found.","messagePattern":"File (.+?) not found\\.","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"metagpt/document.py","lineNumber":79,"sourceCode":"    Document: Handles operations related to document files.\n    \"\"\"\n\n    path: Path = Field(default=None)\n    name: str = Field(default=\"\")\n    content: str = Field(default=\"\")\n\n    # metadata? in content perhaps.\n    author: str = Field(default=\"\")\n    status: DocumentStatus = Field(default=DocumentStatus.DRAFT)\n    reviews: list = Field(default_factory=list)\n\n    @classmethod\n    def from_path(cls, path: Path):\n        \"\"\"\n        Create a Document instance from a file path.\n        \"\"\"\n        if not path.exists():\n            raise FileNotFoundError(f\"File {path} not found.\")\n        content = path.read_text()\n        return cls(content=content, path=path)\n\n    @classmethod\n    def from_text(cls, text: str, path: Optional[Path] = None):\n        \"\"\"\n        Create a Document from a text string.\n        \"\"\"\n        return cls(content=text, path=path)\n\n    def to_path(self, path: Optional[Path] = None):\n        \"\"\"\n        Save content to the specified file path.\n        \"\"\"\n        if path is not None:\n            self.path = path\n\n        if self.path is None:","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/document.py#L61-L97","documentation":"Document.from_path (metagpt/document.py) constructs a Document from a file by first checking Path.exists(); a missing path raises FileNotFoundError with the offending path in the message. This is a caller-input guard before read_text() would fail with a less clear error.","triggerScenarios":"Document.from_path(Path('docs/prd.txt')) when the file was never created, was deleted, or the path is relative and resolved against the wrong working directory.","commonSituations":"Referencing PRD/design docs that a prior pipeline step failed to write; wrong cwd when using relative paths; typos or stale filenames after renames; race with another process still writing the file.","solutions":["Check path.exists() and resolve to an absolute path before calling from_path.","Verify the producing step (e.g. WritePrd) succeeded and actually wrote the file.","Fix the filename or regenerate the document."],"exampleFix":"# before\ndoc = Document.from_path(Path('requirements/old_name.txt'))  # FileNotFoundError\n\n# after\np = Path('requirements/requirement.txt').resolve()\nif not p.exists():\n    raise SystemExit(f'missing {p}')\ndoc = Document.from_path(p)","handlingStrategy":"validation","validationCode":"p = p.resolve()\nif not p.is_file():\n    raise FileNotFoundError(f'expected document not found: {p}')\ndoc = Document.from_path(p)","typeGuard":"def is_existing_file(p: Path) -> TypeGuard[Path]:\n    return p.exists() and p.is_file()","tryCatchPattern":"try:\n    doc = Document.from_path(p)\nexcept FileNotFoundError:\n    doc = Document.from_text('', path=p)  # or regenerate the file upstream","preventionTips":["Resolve paths to absolute form before use.","Run pipeline steps in dependency order so producers write files before consumers read them.","Check existence and log a clear message rather than letting the framework raise."],"tags":["file-not-found","document","path"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}