opendatalab/MinerU · error · FileNotFoundError

Missing middle json file: {middle_json_path}

Error message

Missing middle json file: {middle_json_path}

What it means

FileNotFoundError from regenerate_client_side_outputs(): the client-side renderer expects {doc_stem}_middle.json inside parse_dir (the staged/finalized server artifact). If the file is absent — never downloaded, deleted, or a wrong doc_stem/parse_dir was passed — generation cannot proceed.

Source

Thrown at mineru/cli/client_side_output.py:56

    path.write_text(
        json.dumps(payload, ensure_ascii=False, indent=4),
        encoding="utf-8",
    )


def regenerate_client_side_outputs(
    parse_dir: str | Path,
    doc_stem: str,
) -> tuple[Path, ...]:
    """读取服务端 staged/finalized middle json,并在客户端覆盖生成最终输出产物。"""
    parse_dir = Path(parse_dir)
    middle_json_path = parse_dir / f"{doc_stem}_middle.json"
    markdown_path = parse_dir / f"{doc_stem}.md"
    content_list_path = parse_dir / f"{doc_stem}_content_list.json"
    content_list_v2_path = parse_dir / f"{doc_stem}_content_list_v2.json"

    if not middle_json_path.exists():
        raise FileNotFoundError(f"Missing middle json file: {middle_json_path}")

    middle_json = json.loads(middle_json_path.read_text(encoding="utf-8"))
    if not isinstance(middle_json, dict):
        raise ValueError("middle_json must be a dict.")
    backend = middle_json.get("_backend")
    pdf_info = middle_json.get("pdf_info")
    if backend not in SUPPORTED_BACKENDS:
        raise ValueError(
            f"Unsupported middle json backend for client-side output generation: {backend}"
        )
    if not isinstance(pdf_info, list):
        raise ValueError("middle_json must contain a list field named pdf_info.")

    if backend in PDF_BACKENDS:
        finalize_client_side_middle_json(middle_json)
        pdf_info = middle_json["pdf_info"]

    make_func = _select_union_make(backend)

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Verify the file exists: ls {parse_dir}/{doc_stem}_middle.json before calling
  2. Pass the document stem without extension (Path(pdf).stem), and match the server's sanitized name
  3. Re-run the parse (or re-download results) ensuring middle-json delivery is enabled
  4. Check that you pointed parse_dir at the directory that actually holds the parse outputs, not its parent

Example fix

# before
regenerate_client_side_outputs(parse_dir=out, doc_stem='report.pdf')

# after
regenerate_client_side_outputs(parse_dir=out, doc_stem='report')
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

middle = Path(parse_dir) / f"{Path(doc_stem).stem}_middle.json"
if not middle.exists():
    raise SystemExit(f"middle json missing at {middle}; re-download results or re-run the parse")

Try / catch

try:
    regenerate_client_side_outputs(parse_dir, doc_stem)
except FileNotFoundError as e:
    if "_middle.json" in str(e):
        refetch_results()  # download/parse again, then retry once
    else:
        raise

Prevention

When it happens

Trigger: Calling regenerate_client_side_outputs(parse_dir, doc_stem) where parse_dir does not contain {doc_stem}_middle.json; wrong stem (e.g. passing a name with .pdf extension so the lookup becomes doc.pdf_middle.json); interrupted downloads that skipped the middle json.

Common situations: Output dirs pruned between parse and regenerate; filename stem mismatches after sanitization of special characters; response_format_zip disabled so middle json was never delivered; partial extraction of a result archive.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/db6ebc6f4625224a. Report an issue: GitHub.