{"record":{"id":"ac0b88229f3fe0c9","repo":"FoundationAgents/MetaGPT","slug":"file-path-is-not-set","errorCode":null,"errorMessage":"File path is not set.","messagePattern":"File path is not set\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/document.py","lineNumber":98,"sourceCode":"        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:\n            raise ValueError(\"File path is not set.\")\n\n        self.path.parent.mkdir(parents=True, exist_ok=True)\n        # TODO: excel, csv, json, etc.\n        self.path.write_text(self.content, encoding=\"utf-8\")\n\n    def persist(self):\n        \"\"\"\n        Persist document to disk.\n        \"\"\"\n        return self.to_path()\n\n\nclass IndexableDocument(Document):\n    \"\"\"\n    Advanced document handling: For vector databases or search engines.\n    \"\"\"\n\n    model_config = ConfigDict(arbitrary_types_allowed=True)","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/document.py#L80-L116","documentation":"Document.to_path() writes the document content to disk; it accepts an optional path argument, otherwise using self.path. If neither is set (the Document was created via from_text without a path), it raises ValueError('File path is not set.') because there is nowhere to write. persist() delegates here, so persisting a path-less Document fails the same way.","triggerScenarios":"doc = Document.from_text('hello'); doc.persist() or doc.to_path() — no path was ever assigned. Also happens after explicitly setting doc.path = None.","commonSituations":"Creating documents from LLM output or in-memory strings and forgetting to give them a destination; generic save helpers that call persist() on mixed document sets where some lack paths.","solutions":["Pass a destination: doc.to_path(Path('out/docs/note.md')).","Or set doc.path = Path('out/docs/note.md') before calling persist().","Create the Document with a path up front: Document(content=text, path=Path('out/note.md'))."],"exampleFix":"# before\ndoc = Document.from_text('hello')\ndoc.persist()  # ValueError: File path is not set.\n\n# after\ndoc = Document.from_text('hello', path=Path('out/hello.md'))\ndoc.persist()","handlingStrategy":"validation","validationCode":"if doc.path is None and target is None:\n    raise ValueError('refusing to persist: no destination set')\ndoc.to_path(target or doc.path)","typeGuard":"def has_destination(doc: Document) -> bool:\n    return getattr(doc, 'path', None) is not None","tryCatchPattern":"try:\n    doc.persist()\nexcept ValueError:\n    doc.to_path(Path('out') / 'untitled.md')","preventionTips":["Always create Documents with an explicit path when they will be persisted.","Pass the destination to to_path() in generic save helpers.","Assert doc.path is not None before calling persist()."],"tags":["document","file-write","state","api-misuse"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}