From c12bf49e596c47ae91ce4d3bdfe320a838beaf31 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Sun, 29 Mar 2020 10:58:43 -0700 Subject: Docx reader: better error messages. Distinguish between docx parsing and docx container unpacking errors. --- src/Text/Pandoc/Readers/Docx.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index ac35fa91e..599083949 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -91,14 +91,18 @@ readDocx :: PandocMonad m => ReaderOptions -> B.ByteString -> m Pandoc -readDocx opts bytes - | Right archive <- toArchiveOrFail bytes - , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do - mapM_ (P.report . DocxParserWarning) parserWarnings - (meta, blks) <- docxToOutput opts docx - return $ Pandoc meta blks -readDocx _ _ = - throwError $ PandocSomeError "couldn't parse docx file" +readDocx opts bytes = do + case toArchiveOrFail bytes of + Right archive -> do + case archiveToDocxWithWarnings archive of + Right (docx, parserWarnings) -> do + mapM_ (P.report . DocxParserWarning) parserWarnings + (meta, blks) <- docxToOutput opts docx + return $ Pandoc meta blks + Left docxerr -> throwError $ PandocSomeError $ + "couldn't parse docx file: " <> T.pack (show docxerr) + Left err -> throwError $ PandocSomeError $ + "couldn't unpack docx container: " <> T.pack err data DState = DState { docxAnchorMap :: M.Map T.Text T.Text , docxAnchorSet :: Set.Set T.Text -- cgit v1.2.3