{"record":{"id":"e51bcd0dc465495f","repo":"binary-husky/gpt_academic","slug":"path-suffix-join-sorted-se","errorCode":null,"errorMessage":"不支持的格式: {path.suffix}. 支持的格式: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}","messagePattern":"不支持的格式: (.+?)\\. 支持的格式: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py","lineNumber":136,"sourceCode":"        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\n    def _cleanup_text(self, text: str) -> str:\n        \"\"\"清理文本\n\n        Args:\n            text: 原始文本\n\n        Returns:\n            str: 清理后的文本\n        \"\"\"\n        if self.config.text_cleanup['remove_extra_spaces']:\n            text = ' '.join(text.split())\n","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py#L118-L154","documentation":"Final precondition of MarkdownConverter._validate_file: the suffix is not in SUPPORTED_EXTENSIONS, which for this class is exactly {'.pdf'}. ValueError reports the suffix and the supported list. This converter is PDF-only despite living under the markitdown module — other markitdown-supported types (docx, pptx, xlsx…) are rejected here by design.","triggerScenarios":"Feeding .docx/.md/.html to MarkdownConverter; extension-less PDFs; double extensions like 'file.pdf.exe' or 'file.PDF.' with a trailing dot.","commonSituations":"Assuming the class converts anything markitdown supports because of its name; Windows hiding extensions producing 'paper.pdf.txt'.","solutions":["Convert the source to PDF first (e.g. WordToPdfConverter for docx) before this converter","Rename/copy to give the file a clean '.pdf' suffix if it is genuinely a PDF","Route non-PDF documents to the appropriate reader class in read_fns instead"],"exampleFix":"// before\nconverter.convert('paper.docx')  # 不支持的格式: .docx\n\n// after\npdf = WordToPdfConverter.convert_to_pdf('paper.docx')\nconverter.convert(pdf)","handlingStrategy":"type-guard","validationCode":"if pdf_path.suffix.lower() != '.pdf':\n    raise ValueError('MarkdownConverter accepts only .pdf input')","typeGuard":"from pathlib import Path\n\ndef is_convertible_pdf(v) -> bool:\n    p = Path(v)\n    return p.is_file() and p.suffix.lower() in {'.pdf'}","tryCatchPattern":"try:\n    md = converter.convert(p)\nexcept ValueError as e:\n    if '不支持的格式' in str(e):\n        if p.suffix.lower() in {'.docx', '.doc'}:\n            p = Path(WordToPdfConverter.convert_to_pdf(p)); md = converter.convert(p)\n        else: raise\n    else: raise","preventionTips":["This class is PDF-only; convert other formats to PDF first or route to their dedicated readers","Surface hidden file extensions on Windows to catch 'paper.pdf.txt'","Centralize extension→reader routing in one dispatcher"],"tags":["format-check","file-validation","pdf","routing","python"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}