666ghj/MiroFish · error · FileNotFoundError
文件不存在: {file_path}
Error message
文件不存在: {file_path} What it means
FileNotFoundError raised by FileParser.extract_text when Path(file_path).exists() is false — the caller asked to extract text from a file that is not present at that path on the local filesystem. It is a pre-check before any parsing happens, so no partial work is done.
Source
Thrown at backend/app/utils/file_parser.py:94
"""
suffix = Path(file_path).suffix.lower()
return suffix in cls.SUPPORTED_EXTENSIONS
@classmethod
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提取文本"""View on GitHub (pinned to b5b53acc57)
Solutions
- Verify the path immediately before calling extract_text and resolve relative paths against a known base directory
- Use absolute paths (Path(file).resolve()) when passing files between components
- If the file may legitimately vanish, catch FileNotFoundError and re-fetch/re-upload it
Example fix
# before
text = FileParser.extract_text(f"uploads/{filename}")
# after
path = (UPLOAD_DIR / filename).resolve()
if not path.is_file():
raise FileNotFoundError(f"upload missing: {path}")
text = FileParser.extract_text(str(path)) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
p = Path(file_path)
if not p.is_file():
raise FileNotFoundError(f"missing: {p}") # clear error before parser runs Try / catch
try:
text = FileParser.extract_text(path)
except FileNotFoundError as e:
# re-fetch or notify; nothing was parsed
raise Prevention
- Resolve paths to absolute form at the system boundary
- Don't let temp files be GC'd between upload and parse
- Verify mount points match between services in containerized setups
When it happens
Trigger: Calling extract_text with a path that does not exist: wrong working directory (relative path resolved against a different cwd), file already deleted, typo in the path, or an upload stored elsewhere than expected.
Common situations: Relative paths depending on process cwd, temp files cleaned up before parsing, path received from another service with different mount points in containers.
Related errors
- 不支持的文件格式: {suffix}
- 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/e3824a78a1d8e0d2.
Report an issue: GitHub.