From df74eea69a73ecf446b615189537be831d50952e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 28 Sep 2019 12:36:09 -0700 Subject: Use throwError instead of fail when appropriate. --- src/Text/Pandoc/Readers/Markdown.hs | 5 +++-- src/Text/Pandoc/Writers/Muse.hs | 5 ++++- src/Text/Pandoc/Writers/OOXML.hs | 10 +++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index e00604ea0..46220acc8 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -258,10 +258,11 @@ yamlBsToMeta bstr = do err' pos return . return $ mempty -nodeToKey :: Monad m => YAML.Node YE.Pos -> m Text +nodeToKey :: PandocMonad m => YAML.Node YE.Pos -> m Text nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t -nodeToKey _ = Prelude.fail "Non-string key in YAML mapping" +nodeToKey _ = throwError $ PandocParseError + "Non-string key in YAML mapping" toMetaValue :: PandocMonad m => Text -> MarkdownParser m (F MetaValue) diff --git a/src/Text/Pandoc/Writers/Muse.hs b/src/Text/Pandoc/Writers/Muse.hs index 90b23b6dd..336520634 100644 --- a/src/Text/Pandoc/Writers/Muse.hs +++ b/src/Text/Pandoc/Writers/Muse.hs @@ -26,6 +26,7 @@ even though it is supported only in Emacs Muse. -} module Text.Pandoc.Writers.Muse (writeMuse) where import Prelude +import Control.Monad.Except (throwError) import Control.Monad.Reader import Control.Monad.State.Strict import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace) @@ -37,6 +38,7 @@ import Data.Text (Text) import System.FilePath (takeExtension) import Text.Pandoc.Class (PandocMonad) import Text.Pandoc.Definition +import Text.Pandoc.Error import Text.Pandoc.ImageSize import Text.Pandoc.Options import Text.DocLayout @@ -607,7 +609,8 @@ inlineToMuse (Subscript lst) = do modify $ \st -> st { stUseTags = False } return $ "" <> contents <> "" inlineToMuse SmallCaps {} = - Prelude.fail "SmallCaps should be expanded before normalization" + throwError $ PandocShouldNeverHappenError + "SmallCaps should be expanded before normalization" inlineToMuse (Quoted SingleQuote lst) = do contents <- inlineListToMuse lst modify $ \st -> st { stUseTags = False } diff --git a/src/Text/Pandoc/Writers/OOXML.hs b/src/Text/Pandoc/Writers/OOXML.hs index cd90845af..97ff86156 100644 --- a/src/Text/Pandoc/Writers/OOXML.hs +++ b/src/Text/Pandoc/Writers/OOXML.hs @@ -25,6 +25,8 @@ module Text.Pandoc.Writers.OOXML ( mknode import Prelude import Codec.Archive.Zip import Control.Monad.Reader +import Control.Monad.Except (throwError) +import Text.Pandoc.Error import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as BL import qualified Data.ByteString.Lazy.Char8 as BL8 @@ -50,13 +52,15 @@ renderXml :: Element -> BL.ByteString renderXml elt = BL8.pack "\n" <> UTF8.fromStringLazy (showElement elt) -parseXml :: (PandocMonad m) => Archive -> Archive -> String -> m Element +parseXml :: PandocMonad m => Archive -> Archive -> String -> m Element parseXml refArchive distArchive relpath = case findEntryByPath relpath refArchive `mplus` findEntryByPath relpath distArchive of - Nothing -> Prelude.fail $ relpath ++ " missing in reference file" + Nothing -> throwError $ PandocSomeError $ + relpath ++ " missing in reference file" Just e -> case parseXMLDoc . UTF8.toStringLazy . fromEntry $ e of - Nothing -> Prelude.fail $ relpath ++ " corrupt in reference file" + Nothing -> throwError $ PandocSomeError $ + relpath ++ " corrupt in reference file" Just d -> return d -- Copied from Util -- cgit v1.2.3