binary-husky/gpt_academic · error · ValueError

文件不存在: {path}

Error message

文件不存在: {path}

What it means

First precondition of PaperMetadataExtractor._validate_file (unstructured-based metadata extraction): the resolved path does not exist, raising ValueError('文件不存在: <abs path>'). Same guard pattern as the other readers; message language differs only stylistically ('文件不存在' vs '不是文件' later).

Source

Thrown at crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:104

    def _validate_file(self, file_path: Union[str, Path], max_size_mb: int = 100) -> Path:
        """验证文件

        Args:
            file_path: 文件路径
            max_size_mb: 允许的最大文件大小(MB)

        Returns:
            Path: 验证后的Path对象

        Raises:
            ValueError: 文件不存在、格式不支持或大小超限
            PermissionError: 没有读取权限
        """
        path = Path(file_path).resolve()

        if not path.exists():
            raise ValueError(f"文件不存在: {path}")

        if not path.is_file():
            raise ValueError(f"不是文件: {path}")

        if not os.access(path, os.R_OK):
            raise PermissionError(f"没有读取权限: {path}")

        file_size_mb = path.stat().st_size / (1024 * 1024)
        if file_size_mb > max_size_mb:
            raise ValueError(
                f"文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB"
            )

        if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:
            raise ValueError(
                f"不支持的文件格式: {path.suffix}. "
                f"支持的格式: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}"
            )

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Check the absolute path in the message against the real location; build paths with Path.resolve()
  2. Download remote papers to the log folder first and pass the resulting local path
  3. Fail fast if a preceding step (fetch/copy) did not produce the file instead of passing its would-be path
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

fp = Path(paper_path).resolve()
if not fp.exists():
    raise FileNotFoundError(f'paper not found: {fp}')  # fail before the extractor

Type guard

from pathlib import Path

def is_existing_doc(v) -> bool:
    p = Path(v)
    return p.exists() and p.is_file()

Try / catch

try:
    meta = extractor.extract(fp)
except ValueError as e:
    if '文件不存在' in str(e):
        return retry_after_download(fp)  # fetch remote copy first
    raise

Prevention

When it happens

Trigger: Non-existent paper path, relative path resolved from wrong CWD, file removed between discovery and extraction, or a URL passed instead of a local file (must be downloaded first).

Common situations: Download-then-extract pipelines where the download failed silently; scheduled jobs running from a different working directory; macOS Finder-copied paths with smart quotes.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/fedfd307123a3cce. Report an issue: GitHub.