{"record":{"id":"fedfd307123a3cce","repo":"binary-husky/gpt_academic","slug":"path-fedfd3","errorCode":null,"errorMessage":"文件不存在: {path}","messagePattern":"文件不存在: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py","lineNumber":104,"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\"文件不存在: {path}\")\n\n        if not path.is_file():\n            raise ValueError(f\"不是文件: {path}\")\n\n        if not os.access(path, os.R_OK):\n            raise PermissionError(f\"没有读取权限: {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_mb:.1f}MB) 超过限制 {max_size_mb}MB\"\n            )\n\n        if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:\n            raise ValueError(\n                f\"不支持的文件格式: {path.suffix}. \"\n                f\"支持的格式: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}\"\n            )","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py#L86-L122","documentation":"First precondition of PaperMetadataExtractor._validate_file (unstructured-based metadata extraction): the resolved path does not exist, raising ValueError('文件不存在: <abs path>'). Same guard pattern as the other readers; message language differs only stylistically ('文件不存在' vs '不是文件' later).","triggerScenarios":"Non-existent paper path, relative path resolved from wrong CWD, file removed between discovery and extraction, or a URL passed instead of a local file (must be downloaded first).","commonSituations":"Download-then-extract pipelines where the download failed silently; scheduled jobs running from a different working directory; macOS Finder-copied paths with smart quotes.","solutions":["Check the absolute path in the message against the real location; build paths with Path.resolve()","Download remote papers to the log folder first and pass the resulting local path","Fail fast if a preceding step (fetch/copy) did not produce the file instead of passing its would-be path"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nfp = Path(paper_path).resolve()\nif not fp.exists():\n    raise FileNotFoundError(f'paper not found: {fp}')  # fail before the extractor","typeGuard":"from pathlib import Path\n\ndef is_existing_doc(v) -> bool:\n    p = Path(v)\n    return p.exists() and p.is_file()","tryCatchPattern":"try:\n    meta = extractor.extract(fp)\nexcept ValueError as e:\n    if '文件不存在' in str(e):\n        return retry_after_download(fp)  # fetch remote copy first\n    raise","preventionTips":["Download remote documents to disk and pass the resulting local path","Verify each pipeline stage produced its output file before the next stage runs","Resolve relative paths at intake"],"tags":["file-validation","path-handling","unstructured","metadata","python"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}