diff options
author | John MacFarlane <jgm@berkeley.edu> | 2020-03-29 10:58:43 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2020-03-29 10:59:18 -0700 |
commit | c12bf49e596c47ae91ce4d3bdfe320a838beaf31 (patch) | |
tree | cb5996cd9c27253dca72bb08576731534bf4fa0e /src | |
parent | 7233a7a9329c6c4e75f84b9dca01cb05bf2a55b7 (diff) | |
download | pandoc-c12bf49e596c47ae91ce4d3bdfe320a838beaf31.tar.gz |
Docx reader: better error messages.
Distinguish between docx parsing and docx container
unpacking errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Docx.hs | 20 |
1 files changed, 12 insertions, 8 deletions
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 |