Docx Reader: Throw PandocError on unzip failure

Previously, readDocx would error out if zip-archive failed. We change
the archive extraction step from `toArchive` to `toArchiveOrFail`, which
returns an Either value.
This commit is contained in:
Jesse Rosenthal 2016-05-01 12:17:12 -04:00
parent aa4a1d527a
commit 91dc334249

View file

@ -100,12 +100,13 @@ import Text.Pandoc.Compat.Except
readDocxWithWarnings :: ReaderOptions
-> B.ByteString
-> Either PandocError (Pandoc, MediaBag, [String])
readDocxWithWarnings opts bytes =
case archiveToDocxWithWarnings (toArchive bytes) of
Right (docx, warnings) -> do
readDocxWithWarnings opts bytes
| Right archive <- toArchiveOrFail bytes
, Right (docx, warnings) <- archiveToDocxWithWarnings archive = do
(meta, blks, mediaBag) <- docxToOutput opts docx
return (Pandoc meta blks, mediaBag, warnings)
Left _ -> Left (ParseFailure "couldn't parse docx file")
readDocxWithWarnings _ _ =
Left (ParseFailure "couldn't parse docx file")
readDocx :: ReaderOptions
-> B.ByteString