{"record":{"id":"118e1832829a7c0a","repo":"binary-husky/gpt_academic","slug":"path-118e18","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":124,"sourceCode":"\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            )\n\n        return path\n","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py#L106-L142","documentation":"Second precondition of MarkdownConverter._validate_file: the path exists but is not a regular file (directory, symlink-to-dir, special file), raising ValueError('不是一个文件: <path>'). Means the earlier existence check passed and the type check is what failed.","triggerScenarios":"Passing a directory containing PDFs; an output path accidentally used as input; a glob pattern that matched a directory.","commonSituations":"Batch UIs allowing folder selection; users pasting the containing folder instead of the file.","solutions":["Enumerate the directory's *.pdf files and convert each individually","Fix the upstream path construction so the file (not its parent) is passed","Validate in the UI that the selection is a file"],"exampleFix":"// before\nconverter.convert('papers/')  # 不是一个文件\n\n// after\nfor pdf in Path('papers').glob('*.pdf'):\n    if pdf.is_file():\n        converter.convert(pdf)","handlingStrategy":"type-guard","validationCode":"from pathlib import Path\n\np = Path(target)\nif p.is_dir():\n    raise ValueError('pass a PDF file, not its folder')","typeGuard":"from pathlib import Path\n\ndef is_regular_pdf(v) -> bool:\n    p = Path(v)\n    return p.is_file() and not p.is_dir() and p.suffix.lower() == '.pdf'","tryCatchPattern":"try:\n    md = converter.convert(p)\nexcept ValueError as e:\n    if '不是一个文件' in str(e) and p.is_dir():\n        for pdf in sorted(p.glob('*.pdf')): convert_one(pdf)\n    else: raise","preventionTips":["Expand folder inputs to per-file iteration before calling single-file APIs","Validate selection type in upload UIs"],"tags":["file-validation","directory-vs-file","pdf","markdown","python"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}