{"record":{"id":"401444135fa828a9","repo":"docling-project/docling","slug":"msworddocumentbackend-could-not-load-document-with","errorCode":null,"errorMessage":"MsWordDocumentBackend could not load document with hash {document_hash}","messagePattern":"MsWordDocumentBackend could not load document with hash (.+?)","errorType":"exception","errorClass":"DocumentLoadError","httpStatus":null,"severity":"error","filePath":"docling/backend/msword_backend.py","lineNumber":549,"sourceCode":"    ) -> DocxDocument:\n        try:\n            if isinstance(path_or_stream, Path):\n                with zipfile.ZipFile(path_or_stream) as archive:\n                    if _is_strict_ooxml(archive):\n                        return Document(_normalize_strict_ooxml(archive))\n                return Document(str(path_or_stream))\n            elif isinstance(path_or_stream, BytesIO):\n                with zipfile.ZipFile(path_or_stream) as archive:\n                    if _is_strict_ooxml(archive):\n                        return Document(_normalize_strict_ooxml(archive))\n                path_or_stream.seek(0)\n                return Document(path_or_stream)\n            else:\n                return None\n        except SecurityError:\n            raise\n        except Exception as e:\n            raise DocumentLoadError(\n                f\"MsWordDocumentBackend could not load document with hash {document_hash}\"\n            ) from e\n\n    def _update_history(\n        self,\n        name: str,\n        level: int | None,\n        numid: int | None,\n        ilevel: int | None,\n    ):\n        self.history[\"names\"].append(name)\n        self.history[\"levels\"].append(level)\n\n        self.history[\"numids\"].append(numid)\n        self.history[\"indents\"].append(ilevel)\n\n    def _prev_name(self) -> str | None:\n        return self.history[\"names\"][-1]","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/backend/msword_backend.py#L531-L567","documentation":"DocumentLoadError raised by MsWordDocumentBackend.load_msword_file when python-docx's Document() constructor throws for either a Path or BytesIO input. It wraps any unexpected exception (chained via `from e`) so callers get a docling-native error; SecurityError (zip-slip/bomb) is deliberately re-raised unwrapped.","triggerScenarios":"Loading a corrupt, encrypted/password-protected, or non-ZIP docx: zipfile or docx raises inside Document(...), the except Exception block converts it to DocumentLoadError with the document hash in the message.","commonSituations":"Password-protected Word files from DMS exports, files truncated mid-upload, HTML or RTF renamed to .docx.","solutions":["Confirm the file opens in Word/LibreOffice; if it is password protected, decrypt it first (python-docx cannot open encrypted docx).","If the file is RTF/HTML/legacy .doc, convert it to .docx before passing it to docling.","Re-download or re-transfer truncated files (compare size/hash with the source).","Catch DocumentLoadError and log document_hash to correlate the failure with the ingest record."],"exampleFix":"# before\nresult = converter.convert(Path('report.docx'))  # DocumentLoadError\n\n# after\nfrom docling.exceptions import DocumentLoadError\ntry:\n    result = converter.convert(Path('report.docx'))\nexcept DocumentLoadError as e:\n    logger.error('failed to load %s (hash=%s)', path, e)\n    result = None","handlingStrategy":"try-catch","validationCode":"import zipfile\ntry:\n    with zipfile.ZipFile(path) as z:\n        assert 'word/document.xml' in z.namelist()\nexcept zipfile.BadZipFile:\n    raise ValueError('not a valid docx package')","typeGuard":null,"tryCatchPattern":"from docling.exceptions import DocumentLoadError\ntry:\n    result = converter.convert(path)\nexcept DocumentLoadError as e:\n    logger.error('load failed for %s: %s (cause: %s)', path, e, e.__cause__)","preventionTips":["Decrypt password-protected docx before ingestion","Verify uploads are complete (size/hash) before converting","Inspect e.__cause__ to distinguish corruption from encryption"],"tags":["docx","corrupt-file","load-failure"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}