{"record":{"id":"cd64e23b9c05ea63","repo":"binary-husky/gpt_academic","slug":"path","errorCode":null,"errorMessage":"文件不存在: {path}","messagePattern":"文件不存在: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py","lineNumber":121,"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":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py#L103-L139","documentation":"First precondition of MarkdownConverter._validate_file (the markitdown-based PDF→Markdown converter): the resolved path does not exist, so ValueError('文件不存在: <abs path>') is raised. Identical pattern to the Excel reader's check but for this class, whose SUPPORTED_EXTENSIONS is only {'.pdf'}.","triggerScenarios":"Passing a non-existent PDF path, a relative path resolved from the wrong CWD, or a URL where a local file path is expected.","commonSituations":"Generated temp PDFs (e.g. from a Word→PDF step) referenced under a different name after rename/cleanup; concurrent cleanup deleting the file before conversion.","solutions":["Verify the absolute path shown in the message; construct paths with Path and .resolve()","If chaining conversions (docx→pdf→md), reuse the returned path string from the previous step rather than rebuilding it","Guard against TOCTOU by checking existence immediately before the call in the same process"],"exampleFix":"// before\nmd = converter.convert('out/paper')  # forgot .pdf suffix -> 文件不存在\n\n// after\npdf = word2pdf.convert_to_pdf(docx)   # returns the real path\nmd = converter.convert(pdf)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\npdf = Path(pdf_path).resolve()\nif not pdf.exists():\n    raise FileNotFoundError(f'{pdf} missing; was the PDF step successful?')","typeGuard":"def is_pdf_file(v) -> bool:\n    p = Path(v)\n    return p.is_file() and p.suffix.lower() == '.pdf'","tryCatchPattern":"try:\n    md = converter.convert(pdf)\nexcept ValueError as e:\n    if '文件不存在' in str(e):\n        regenerate_or_relocate_pdf()\n    raise","preventionTips":["In multi-step pipelines pass the previous step's returned path object verbatim","Resolve to absolute paths at ingest","Never assume a conversion produced output — check before chaining"],"tags":["file-validation","path-handling","pdf","markdown","python"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}