From 91dc334249883b658e2b91fce80ced6635e07c28 Mon Sep 17 00:00:00 2001
From: Jesse Rosenthal <jrosenthal@jhu.edu>
Date: Sun, 1 May 2016 12:17:12 -0400
Subject: 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.
---
 src/Text/Pandoc/Readers/Docx.hs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'src')

diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 604bc20de..9c7c3b264 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -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
-- 
cgit v1.2.3