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 readDocxWithWarnings :: ReaderOptions
-> B.ByteString -> B.ByteString
-> Either PandocError (Pandoc, MediaBag, [String]) -> Either PandocError (Pandoc, MediaBag, [String])
readDocxWithWarnings opts bytes = readDocxWithWarnings opts bytes
case archiveToDocxWithWarnings (toArchive bytes) of | Right archive <- toArchiveOrFail bytes
Right (docx, warnings) -> do , Right (docx, warnings) <- archiveToDocxWithWarnings archive = do
(meta, blks, mediaBag) <- docxToOutput opts docx (meta, blks, mediaBag) <- docxToOutput opts docx
return (Pandoc meta blks, mediaBag, warnings) return (Pandoc meta blks, mediaBag, warnings)
Left _ -> Left (ParseFailure "couldn't parse docx file") readDocxWithWarnings _ _ =
Left (ParseFailure "couldn't parse docx file")
readDocx :: ReaderOptions readDocx :: ReaderOptions
-> B.ByteString -> B.ByteString