aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-09-28 12:36:09 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-09-28 12:36:09 -0700
commitdf74eea69a73ecf446b615189537be831d50952e (patch)
tree28061698cb79508b5c93ecf4bd9b424e5f9915ed /src/Text
parentc86691fb84ec830086bc9b5e54b1ec8e41d160c8 (diff)
downloadpandoc-df74eea69a73ecf446b615189537be831d50952e.tar.gz
Use throwError instead of fail when appropriate.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs5
-rw-r--r--src/Text/Pandoc/Writers/Muse.hs5
-rw-r--r--src/Text/Pandoc/Writers/OOXML.hs10
3 files changed, 14 insertions, 6 deletions
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 $ "<sub>" <> contents <> "</sub>"
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 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\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