{"record":{"id":"db6ebc6f4625224a","repo":"opendatalab/MinerU","slug":"missing-middle-json-file-middle-json-path","errorCode":null,"errorMessage":"Missing middle json file: {middle_json_path}","messagePattern":"Missing middle json file: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"error","filePath":"mineru/cli/client_side_output.py","lineNumber":56,"sourceCode":"    path.write_text(\n        json.dumps(payload, ensure_ascii=False, indent=4),\n        encoding=\"utf-8\",\n    )\n\n\ndef regenerate_client_side_outputs(\n    parse_dir: str | Path,\n    doc_stem: str,\n) -> tuple[Path, ...]:\n    \"\"\"读取服务端 staged/finalized middle json，并在客户端覆盖生成最终输出产物。\"\"\"\n    parse_dir = Path(parse_dir)\n    middle_json_path = parse_dir / f\"{doc_stem}_middle.json\"\n    markdown_path = parse_dir / f\"{doc_stem}.md\"\n    content_list_path = parse_dir / f\"{doc_stem}_content_list.json\"\n    content_list_v2_path = parse_dir / f\"{doc_stem}_content_list_v2.json\"\n\n    if not middle_json_path.exists():\n        raise FileNotFoundError(f\"Missing middle json file: {middle_json_path}\")\n\n    middle_json = json.loads(middle_json_path.read_text(encoding=\"utf-8\"))\n    if not isinstance(middle_json, dict):\n        raise ValueError(\"middle_json must be a dict.\")\n    backend = middle_json.get(\"_backend\")\n    pdf_info = middle_json.get(\"pdf_info\")\n    if backend not in SUPPORTED_BACKENDS:\n        raise ValueError(\n            f\"Unsupported middle json backend for client-side output generation: {backend}\"\n        )\n    if not isinstance(pdf_info, list):\n        raise ValueError(\"middle_json must contain a list field named pdf_info.\")\n\n    if backend in PDF_BACKENDS:\n        finalize_client_side_middle_json(middle_json)\n        pdf_info = middle_json[\"pdf_info\"]\n\n    make_func = _select_union_make(backend)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/cli/client_side_output.py#L38-L74","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the file exists: ls {parse_dir}/{doc_stem}_middle.json before calling","Pass the document stem without extension (Path(pdf).stem), and match the server's sanitized name","Re-run the parse (or re-download results) ensuring middle-json delivery is enabled","Check that you pointed parse_dir at the directory that actually holds the parse outputs, not its parent"],"exampleFix":"# before\nregenerate_client_side_outputs(parse_dir=out, doc_stem='report.pdf')\n\n# after\nregenerate_client_side_outputs(parse_dir=out, doc_stem='report')","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nmiddle = Path(parse_dir) / f\"{Path(doc_stem).stem}_middle.json\"\nif not middle.exists():\n    raise SystemExit(f\"middle json missing at {middle}; re-download results or re-run the parse\")","typeGuard":null,"tryCatchPattern":"try:\n    regenerate_client_side_outputs(parse_dir, doc_stem)\nexcept FileNotFoundError as e:\n    if \"_middle.json\" in str(e):\n        refetch_results()  # download/parse again, then retry once\n    else:\n        raise","preventionTips":["Derive doc_stem with Path(name).stem — never pass a filename with an extension","Check the staged directory listing before rendering","Keep the whole staged output directory intact until rendering completes"],"tags":["client-side","middle-json","file-not-found","artifacts"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}