From 5ade1bdf7286b204bc8433bf267e22977bf4aba1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 20 Sep 2026 20:09:47 -0700 Subject: [PATCH] Docx writer: properly signal error if reference docx can't be parsed. --- src/Text/Pandoc/Writers/Docx.hs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index a36d3c2ea..8b0690fdf 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -23,6 +23,7 @@ import Codec.Archive.Zip findEntryByPath, fromArchive, toArchive, + toArchiveOrFail, toEntry, Entry(eRelativePath) ) import Control.Monad (MonadPlus(mplus), foldM) @@ -506,10 +507,21 @@ loadArchives opts = do P.setUserDataDir oldUserDataDir let distArchive = toArchive $ BL.fromStrict res refArchive <- case writerReferenceDoc opts of - Just f -> toArchive . BL.fromStrict . fst + Just f -> do + arch <- toArchiveOrFail . BL.fromStrict . fst <$> P.fetchItem (T.pack f) - Nothing -> toArchive . BL.fromStrict <$> - readDataFile "reference.docx" + case arch of + Left err -> throwError $ PandocParseError $ + "Could not parse reference-doc " <> + tshow f <> ": " <> T.pack err + Right x -> pure x + Nothing -> do + arch <- toArchiveOrFail . BL.fromStrict <$> + readDataFile "reference.docx" + case arch of + Left err -> throwError $ PandocParseError $ + "Could not parse reference.docx: " <> T.pack err + Right x -> pure x return (refArchive, distArchive, username, utctime) isWmlNamespace :: QName -> Bool