From 0459e2cf53ad8670e6692020f5864eafffe2caf9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 18 Feb 2024 10:51:56 +0000 Subject: Improve error message when failing to find the body element in a document --- lib/docx/document-xml-reader.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/docx/document-xml-reader.js') diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js index c5472c2..9543ed8 100644 --- a/lib/docx/document-xml-reader.js +++ b/lib/docx/document-xml-reader.js @@ -10,6 +10,10 @@ function DocumentXmlReader(options) { function convertXmlToDocument(element) { var body = element.first("w:body"); + if (body == null) { + throw new Error("Could not find the body element: are you sure this is a docx file?"); + } + var result = bodyReader.readXmlElements(body.children) .map(function(children) { return new documents.Document(children, { -- cgit v1.2.3