{"record":{"id":"8c994d04144fefd8","repo":"can1357/oh-my-pi","slug":"invalid-docx-missing-document-body","errorCode":null,"errorMessage":"Invalid DOCX: missing document body","messagePattern":"Invalid DOCX: missing document body","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/utils/src/docx/converter.ts","lineNumber":678,"sourceCode":"\tif (!documentXml) throw new Error(\"Invalid DOCX: missing word/document.xml\");\n\tconst context: ConversionContext = {\n\t\tentries,\n\t\trelationships: parseRelationships(archiveEntryText(entries, \"word/_rels/document.xml.rels\")),\n\t\tcontentTypes: parseContentTypes(archiveEntryText(entries, \"[Content_Types].xml\")),\n\t\tstyles: parseStyles(archiveEntryText(entries, \"word/styles.xml\")),\n\t\tnumbering: parseNumbering(archiveEntryText(entries, \"word/numbering.xml\")),\n\t\tmessages: [],\n\t\twarnedStyles: new Set(),\n\t\tcustomStyles: parseCustomStyles(options.styleMap),\n\t\tincludeDefaultStyleMap: options.includeDefaultStyleMap !== false,\n\t\tconvertImage: options.convertImage ?? defaultImageConverter(),\n\t\tfootnotes: parseFootnotes(archiveEntryText(entries, \"word/footnotes.xml\")),\n\t\tusedFootnotes: [],\n\t\tfootnoteOrdinals: new Map(),\n\t};\n\tconst document = parseXml(documentXml);\n\tconst body = firstChild(document, \"body\");\n\tif (!body) throw new Error(\"Invalid DOCX: missing document body\");\n\tconst value = renderBlocks(await parseBlocks(childElements(body), context)) + (await renderFootnotes(context));\n\treturn { value, messages: context.messages };\n}\n","sourceCodeStart":660,"sourceCodeEnd":682,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/docx/converter.ts#L660-L682","documentation":"After locating word/document.xml, convertToHtml() parses it and requires a <w:body> child element, which contains the document's block content. A document.xml without a body is structurally invalid for OOXML, so rendering cannot proceed and this error is thrown.","triggerScenarios":"Calling convertToHtml() on a DOCX whose word/document.xml lacks a <w:body> element: hand-crafted or programmatically generated XML missing the body, an XML document saved with the wrong root, or a file where document.xml is actually a non-document OOXML part.","commonSituations":"Generating DOCX with a custom writer that emits <w:document> without <w:body>; template post-processing that strips the body; zipping an arbitrary XML file as word/document.xml to satisfy format checks.","solutions":["Regenerate or fix the DOCX so word/document.xml contains a <w:body> element (use a library like docx or save from Word).","Inspect the archive: extract and view word/document.xml to confirm the <w:document ...><w:body> structure.","If generating DOCX programmatically, emit the body even for empty documents: <w:body></w:body>.","Re-save the file via LibreOffice headless (`soffice --convert-to docx`) to normalize the XML structure."],"exampleFix":"// before (generated document.xml)\n<?xml version=\"1.0\"?><w:document xmlns:w=\"...\"></w:document>\n\n// after\n<?xml version=\"1.0\"?><w:document xmlns:w=\"...\"><w:body><w:p/></w:body></w:document>","handlingStrategy":"validation","validationCode":"import { readArchiveEntries, archiveEntryText } from \"./xml-helpers\"; // same helpers the library uses\nconst entries = await readArchiveEntries({ bytes, format: \"zip\" });\nconst doc = archiveEntryText(entries, \"word/document.xml\");\nif (!doc || !/<w:body[\\s>]/.test(doc)) throw new Error(\"DOCX document.xml has no <w:body>\");","typeGuard":null,"tryCatchPattern":"try {\n  return await convertToHtml(input);\n} catch (err) {\n  if (err instanceof Error && err.message === \"Invalid DOCX: missing document body\") {\n    // regenerate/normalize the file with soffice --convert-to docx, or reject the document\n  } else throw err;\n}","preventionTips":["Generate DOCX with an established library (e.g. docx) that always emits <w:body>.","Inspect word/document.xml after programmatic generation to confirm the <w:document><w:body> structure.","Emit an empty <w:body></w:body> even for empty documents.","Normalize third-party files once via `soffice --headless --convert-to docx` in your pipeline."],"tags":["docx","xml","validation","file-format"],"backgroundTag":"invalid-docx","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}