{"record":{"id":"512589dc1dfc8bb6","repo":"PaddlePaddle/PaddleOCR","slug":"failed-to-convert-file-path-name-e","errorCode":null,"errorMessage":"Failed to convert {file_path.name}: {e}","messagePattern":"Failed to convert (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"paddleocr/_doc2md/core.py","lineNumber":58,"sourceCode":"\n    Examples:\n        >>> from paddleocr import doc2md_convert\n        >>> result = doc2md_convert(\"report.docx\")\n        >>> print(result.markdown)\n    \"\"\"\n    file_path = Path(source)\n\n    if not file_path.exists():\n        raise FileNotFoundError(f\"File not found: {file_path}\")\n\n    converter = default_registry.get_converter(file_path)\n\n    try:\n        result = converter.convert_file(file_path, **kwargs)\n    except Exception as e:\n        if isinstance(e, (FileNotFoundError, ValueError, RuntimeError)):\n            raise\n        raise RuntimeError(f\"Failed to convert {file_path.name}: {e}\") from e\n\n    if output:\n        output_path = Path(output)\n        output_path.parent.mkdir(parents=True, exist_ok=True)\n        output_path.write_text(result.markdown, encoding=\"utf-8\")\n        if result.images:\n            images_dir = output_path.parent / \"images\"\n            images_dir.mkdir(exist_ok=True)\n            for rel_path, img_bytes in result.images.items():\n                img_file = output_path.parent / rel_path\n                img_file.write_bytes(img_bytes)\n\n    return result\n\n\ndef supported_formats() -> list[str]:\n    \"\"\"Return a list of supported file extensions.\"\"\"\n    return default_registry.supported_extensions()","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_doc2md/core.py#L40-L76","documentation":"RuntimeError raised by doc2md_convert as a catch-all wrapper when converter.convert_file raises anything other than FileNotFoundError, ValueError, or RuntimeError. The original exception is chained (from e) and the message names the offending file, preserving the root cause while normalizing the error type.","triggerScenarios":"A corrupted or password-protected Office file that makes python-docx/openpyxl/python-pptx throw a package-specific exception; XML parse errors inside a malformed .docx; unexpected KeyError/TypeError from exotic documents.","commonSituations":"Batch-ingesting untrusted user documents; partially downloaded or truncated files; documents with unusual OOXML structures.","solutions":["Read the chained cause (e.__cause__) to find the real failure","Open the file in its native app (Word/Excel/PowerPoint) to check for corruption or passwords","Isolate and skip the bad file, then report it for manual repair"],"exampleFix":"# before\nfor f in files:\n    doc2md_convert(f)\n# after\nfor f in files:\n    try:\n        doc2md_convert(f)\n    except RuntimeError as e:\n        logger.warning('skipped %s: %s (cause: %r)', f, e, e.__cause__)\n        continue","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = doc2md_convert(path)\nexcept RuntimeError as e:\n    cause = e.__cause__\n    log.error('conversion failed for %s: %s | cause=%r', path, e, cause)\n    quarantine(path)  # move bad file aside, continue batch","preventionTips":["Always log e.__cause__; the wrapper hides the real exception type","Quarantine failing files in batch pipelines instead of aborting","Pre-validate that files open in their native format for untrusted inputs"],"tags":["doc2md","wrapper","error-handling"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}