666ghj/MiroFish · error · ValueError
不支持的文件格式: {suffix}
Error message
不支持的文件格式: {suffix} What it means
ValueError raised by FileParser.extract_text when the lowercased file suffix is not in SUPPORTED_EXTENSIONS. The parser supports only a fixed set (pdf, md/markdown, txt and dispatch equivalents), and rejects anything else before attempting extraction.
Source
Thrown at backend/app/utils/file_parser.py:99
def extract_text(cls, file_path: str) -> str:
"""
从文件中提取文本
Args:
file_path: 文件路径
Returns:
提取的文本内容
"""
path = Path(file_path)
if not path.exists():
raise FileNotFoundError(f"文件不存在: {file_path}")
suffix = path.suffix.lower()
if suffix not in cls.SUPPORTED_EXTENSIONS:
raise ValueError(f"不支持的文件格式: {suffix}")
if suffix == '.pdf':
return cls._extract_from_pdf(file_path)
elif suffix in {'.md', '.markdown'}:
return cls._extract_from_md(file_path)
elif suffix == '.txt':
return cls._extract_from_txt(file_path)
raise ValueError(f"无法处理的文件格式: {suffix}")
@staticmethod
def _extract_from_pdf(file_path: str) -> str:
"""从PDF提取文本"""
try:
import fitz # PyMuPDF
except ImportError:
raise ImportError("需要安装PyMuPDF: pip install PyMuPDF")
View on GitHub (pinned to b5b53acc57)
Solutions
- Restrict uploads at the API boundary to SUPPORTED_EXTENSIONS so the error never reaches the parser
- Convert unsupported documents to pdf/txt/md before extraction (e.g. external converter)
- Extend SUPPORTED_EXTENSIONS plus add a matching _extract_from_* branch if a new format is genuinely needed
Example fix
# before
text = FileParser.extract_text(str(upload)) # .docx -> ValueError
# after
ALLOWED = set(FileParser.SUPPORTED_EXTENSIONS)
if upload.suffix.lower() not in ALLOWED:
raise HTTPException(415, f"unsupported file type: {upload.suffix}")
text = FileParser.extract_text(str(upload)) Defensive patterns
Strategy: validation
Validate before calling
suffix = Path(file_path).suffix.lower()
if suffix not in FileParser.SUPPORTED_EXTENSIONS:
raise ValueError(f"reject early: {suffix} not supported") Try / catch
try:
text = FileParser.extract_text(path)
except ValueError as e:
return http_error(415, str(e)) Prevention
- Enforce the extension allow-list at the upload endpoint, not only in the parser
- Keep frontend accepted-types list in sync with SUPPORTED_EXTENSIONS
- Return 415 Unsupported Media Type for unsupported uploads
When it happens
Trigger: Calling extract_text on a file like document.docx, file.json, or archive.zip — any extension outside the supported set. Also a file with no suffix at all (path.suffix is ''), which is likewise not in the set.
Common situations: User uploads a format the backend never planned to support (docx, html, epub), frontend validation gap letting unsupported types through, or double extensions where the final suffix is the unsupported one.
Related errors
- 文件不存在: {file_path}
- t('step5.selectAgentFirst')
- graph_id is required
- At least one text chunk is required
- batch_size must be between 1 and 350
AI-assisted analysis of 666ghj/MiroFish@b5b53acc57 (2026-08-14).
Data as JSON: /api/errors/4cbeb22a8d63d2a7.
Report an issue: GitHub.