{"record":{"id":"18aea996858ead3b","repo":"crewAIInc/crewAI","slug":"file-not-found-self-path","errorCode":null,"errorMessage":"File not found: {self.path}","messagePattern":"File not found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-files/src/crewai_files/core/sources.py","lineNumber":234,"sourceCode":"    _content_type: str = PrivateAttr()\n\n    @model_validator(mode=\"after\")\n    def _validate_file_exists(self) -> FilePath:\n        \"\"\"Validate that the file exists, is secure, and within size limits.\"\"\"\n        from crewai_files.processing.exceptions import FileTooLargeError\n\n        path_str = str(self.path)\n        if \"..\" in path_str:\n            raise ValueError(f\"Path traversal not allowed: {self.path}\")\n\n        if self.path.is_symlink():\n            resolved = self.path.resolve()\n            cwd = Path.cwd().resolve()\n            if not str(resolved).startswith(str(cwd)):\n                raise ValueError(f\"Symlink escapes allowed directory: {self.path}\")\n\n        if not self.path.exists():\n            raise ValueError(f\"File not found: {self.path}\")\n        if not self.path.is_file():\n            raise ValueError(f\"Path is not a file: {self.path}\")\n\n        actual_size = self.path.stat().st_size\n        if actual_size > self.max_size_bytes:\n            raise FileTooLargeError(\n                f\"File exceeds max size ({actual_size} > {self.max_size_bytes})\",\n                file_name=str(self.path),\n                actual_size=actual_size,\n                max_size=self.max_size_bytes,\n            )\n\n        self._content_type = detect_content_type_from_path(self.path, self.path.name)\n        return self\n\n    @property\n    def filename(self) -> str:\n        \"\"\"Get the filename from the path.\"\"\"","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/core/sources.py#L216-L252","documentation":"Straightforward existence check in FilePath's model_validator: Path.exists() is False for the supplied path, so validation fails with the path in the message. It runs after the traversal and symlink guards, so if you get this (rather than error 131/132) the path passed security checks but nothing is there — deleted, not yet written, typo, or wrong working directory for a relative path.","triggerScenarios":"FilePath(path=Path(\"uploads/x.pdf\")) before the upload completed; relative path resolved against an unexpected CWD; race where the file was removed between listing and validation.","commonSituations":"Async pipelines that construct the model before the writer task finishes; relative paths in containers/servers where CWD differs from the app root; files cleaned up by temp-dir lifecycle (pytest tmp_path deleted).","solutions":["Check Path(...).exists() (and log the absolute path via .resolve()) right before constructing FilePath.","Use absolute paths derived from a known anchor (__file__ or a configured ROOT) rather than CWD-relative strings.","In async pipelines, await the producer/write task before building the file source."],"exampleFix":"# before\nsrc = FilePath(path=Path(\"uploads/x.pdf\"))  # written later by another task\n\n# after\nawait write_task.join()\np = UPLOAD_DIR / \"x.pdf\"\nassert p.exists(), f\"missing {p.resolve()}\"\nsrc = FilePath(path=p)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef file_ready(p: Path) -> bool:\n    return p.exists() and p.is_file()","typeGuard":null,"tryCatchPattern":"try:\n    FilePath(path=p)\nexcept ValidationError as e:\n    if \"File not found\" in str(e):\n        # re-check with absolute path for logging\n        print(\"missing:\", p.resolve())","preventionTips":["Construct FilePath only after the writing task/transaction commits.","Log p.resolve() (absolute) when relative paths misbehave — usually a CWD mismatch.","Use absolute paths anchored to a configured ROOT constant."],"tags":["filesystem","validation","file-sources","race-condition"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}