FoundationAgents/MetaGPT · error · FileNotFoundError
File {path} not found.
Error message
File {path} not found. What it means
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.
Source
Thrown at metagpt/document.py:79
Document: Handles operations related to document files.
"""
path: Path = Field(default=None)
name: str = Field(default="")
content: str = Field(default="")
# metadata? in content perhaps.
author: str = Field(default="")
status: DocumentStatus = Field(default=DocumentStatus.DRAFT)
reviews: list = Field(default_factory=list)
@classmethod
def from_path(cls, path: Path):
"""
Create a Document instance from a file path.
"""
if not path.exists():
raise FileNotFoundError(f"File {path} not found.")
content = path.read_text()
return cls(content=content, path=path)
@classmethod
def from_text(cls, text: str, path: Optional[Path] = None):
"""
Create a Document from a text string.
"""
return cls(content=text, path=path)
def to_path(self, path: Optional[Path] = None):
"""
Save content to the specified file path.
"""
if path is not None:
self.path = path
if self.path is None:View on GitHub (pinned to 11cdf466d0)
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.
Example fix
# before
doc = Document.from_path(Path('requirements/old_name.txt')) # FileNotFoundError
# after
p = Path('requirements/requirement.txt').resolve()
if not p.exists():
raise SystemExit(f'missing {p}')
doc = Document.from_path(p) Defensive patterns
Strategy: validation
Validate before calling
p = p.resolve()
if not p.is_file():
raise FileNotFoundError(f'expected document not found: {p}')
doc = Document.from_path(p) Type guard
def is_existing_file(p: Path) -> TypeGuard[Path]:
return p.exists() and p.is_file() Try / catch
try:
doc = Document.from_path(p)
except FileNotFoundError:
doc = Document.from_text('', path=p) # or regenerate the file upstream Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- File {data_path} not found.
- File {file_path} not found
- json_file: {json_file} not exist, return []
- json_file: {jsonl_file} not exist, return []
- {image_path_or_pil} not exists
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/8de0cb4051db71d9.
Report an issue: GitHub.