{"record":{"id":"0deee7dc8000f506","repo":"binary-husky/gpt_academic","slug":"file-not-found-path-0deee7","errorCode":null,"errorMessage":"File not found: {path}","messagePattern":"File not found: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crazy_functions/doc_fns/read_fns/unstructured_all/unstructured_reader.py","lineNumber":115,"sourceCode":"\n    def _validate_file(self, file_path: Union[str, Path], max_size_mb: int = 100) -> Path:\n        \"\"\"验证文件\n\n        Args:\n            file_path: 文件路径\n            max_size_mb: 允许的最大文件大小(MB)\n\n        Returns:\n            Path: 验证后的Path对象\n\n        Raises:\n            ValueError: 文件不存在、格式不支持或大小超限\n            PermissionError: 没有读取权限\n        \"\"\"\n        path = Path(file_path).resolve()\n\n        if not path.exists():\n            raise ValueError(f\"File not found: {path}\")\n\n        if not path.is_file():\n            raise ValueError(f\"Not a file: {path}\")\n\n        if not os.access(path, os.R_OK):\n            raise PermissionError(f\"No read permission: {path}\")\n\n        file_size_mb = path.stat().st_size / (1024 * 1024)\n        if file_size_mb > max_size_mb:\n            raise ValueError(\n                f\"File size ({file_size_mb:.1f}MB) exceeds limit of {max_size_mb}MB\"\n            )\n\n        if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:\n            raise ValueError(\n                f\"Unsupported format: {path.suffix}. \"\n                f\"Supported: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}\"\n            )","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/doc_fns/read_fns/unstructured_all/unstructured_reader.py#L97-L133","documentation":"UnstructuredReader's English-language counterpart of the missing-path check: _validate_file raises ValueError('File not found: ...') when Path(file_path).resolve() does not exist. Fail-fast validation done before any parsing so callers get a precise reason.","triggerScenarios":"Calling UnstructuredReader.read/extract with a path that doesn't exist on disk: typo, stale path from a previous run, file already deleted by cleanup, relative path resolved against an unexpected CWD (resolve() makes it absolute against the process CWD).","commonSituations":"Temp files garbage-collected between scheduling and execution; path from user input taken literally; app deployed in a container where the file lives on a volume that isn't mounted; race with antivirus/quarantine on Windows.","solutions":["Verify the path exists (and is readable) before calling the reader; log the resolved absolute path.","If the path is relative, anchor it explicitly with Path(__file__).parent / ... or a configured base dir instead of relying on CWD.","Check mount/volume presence in containerized deployments before the read call.","Regenerate or re-download the source file if a cleanup job removed it."],"exampleFix":"# before\nreader.read('uploads/' + name)  # may resolve against wrong CWD\n\n# after\nfrom pathlib import Path\np = (UPLOAD_DIR / name).resolve()\nif not p.exists():\n    raise FileNotFoundError(name)\nreader.read(p)","handlingStrategy":"validation","validationCode":"from pathlib import Path\np = Path(file_path).resolve()\nif not p.exists():\n    raise FileNotFoundError(file_path)","typeGuard":"def file_exists(path: str) -> bool:\n    from pathlib import Path\n    return Path(path).resolve().exists()","tryCatchPattern":"try:\n    reader.read(fp)\nexcept ValueError as e:\n    if str(e).startswith('File not found'):\n        re_acquire(fp)  # re-download/regenerate\n    raise","preventionTips":["Anchor relative paths to a configured base directory.","Verify volumes are mounted before batch runs.","Don't reuse paths across restarts without re-checking.","Log resolved absolute paths for every read."],"tags":["filesystem","validation","path","python"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}