git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: better error messages.
c12bf49John MacFarlane
src/Text/Pandoc/Readers/Docx.hs+12−8
@@ -91,14 +91,18 @@ readDocx :: PandocMonad m
91 => ReaderOptions
91 => ReaderOptions
92 -> B.ByteString
92 -> B.ByteString
93 -> m Pandoc
93 -> m Pandoc
94−readDocx opts bytes
94+readDocx opts bytes = do
95− | Right archive <- toArchiveOrFail bytes
95+ case toArchiveOrFail bytes of
96+ Right archive -> do
96− , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
97+ case archiveToDocxWithWarnings archive of
98+ Right (docx, parserWarnings) -> do
97− mapM_ (P.report . DocxParserWarning) parserWarnings
99+ mapM_ (P.report . DocxParserWarning) parserWarnings
98− (meta, blks) <- docxToOutput opts docx
100+ (meta, blks) <- docxToOutput opts docx
99− return $ Pandoc meta blks
101+ return $ Pandoc meta blks
100−readDocx _ _ =
101− throwError $ PandocSomeError "couldn't parse docx file"
102+ Left docxerr -> throwError $ PandocSomeError $
103+ "couldn't parse docx file: " <> T.pack (show docxerr)
104+ Left err -> throwError $ PandocSomeError $
105+ "couldn't unpack docx container: " <> T.pack err
102
106
103data DState = DState { docxAnchorMap :: M.Map T.Text T.Text
107data DState = DState { docxAnchorMap :: M.Map T.Text T.Text
104 , docxAnchorSet :: Set.Set T.Text
108 , docxAnchorSet :: Set.Set T.Text