git.iko.soy/typeable/pandoc
on master help sign in
Use throwError instead of fail when appropriate.
df74eeaJohn MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+3−2
@@ -258,10 +258,11 @@ yamlBsToMeta bstr = do
258 err' pos
258 err' pos
259 return . return $ mempty
259 return . return $ mempty
260
260
261−nodeToKey :: Monad m => YAML.Node YE.Pos -> m Text
261+nodeToKey :: PandocMonad m => YAML.Node YE.Pos -> m Text
262nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t
262nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t
263nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t
263nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t
264+nodeToKey _ = throwError $ PandocParseError
264−nodeToKey _ = Prelude.fail "Non-string key in YAML mapping"
265+ "Non-string key in YAML mapping"
265
266
266toMetaValue :: PandocMonad m
267toMetaValue :: PandocMonad m
267 => Text -> MarkdownParser m (F MetaValue)
268 => Text -> MarkdownParser m (F MetaValue)
src/Text/Pandoc/Writers/Muse.hs+4−1
@@ -26,6 +26,7 @@ even though it is supported only in Emacs Muse.
26-}
26-}
27module Text.Pandoc.Writers.Muse (writeMuse) where
27module Text.Pandoc.Writers.Muse (writeMuse) where
28import Prelude
28import Prelude
29+import Control.Monad.Except (throwError)
29import Control.Monad.Reader
30import Control.Monad.Reader
30import Control.Monad.State.Strict
31import Control.Monad.State.Strict
31import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace)
32import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace)
@@ -37,6 +38,7 @@ import Data.Text (Text)
37import System.FilePath (takeExtension)
38import System.FilePath (takeExtension)
38import Text.Pandoc.Class (PandocMonad)
39import Text.Pandoc.Class (PandocMonad)
39import Text.Pandoc.Definition
40import Text.Pandoc.Definition
41+import Text.Pandoc.Error
40import Text.Pandoc.ImageSize
42import Text.Pandoc.ImageSize
41import Text.Pandoc.Options
43import Text.Pandoc.Options
42import Text.DocLayout
44import Text.DocLayout
@@ -607,7 +609,8 @@ inlineToMuse (Subscript lst) = do
607 modify $ \st -> st { stUseTags = False }
609 modify $ \st -> st { stUseTags = False }
608 return $ "<sub>" <> contents <> "</sub>"
610 return $ "<sub>" <> contents <> "</sub>"
609inlineToMuse SmallCaps {} =
611inlineToMuse SmallCaps {} =
612+ throwError $ PandocShouldNeverHappenError
610− Prelude.fail "SmallCaps should be expanded before normalization"
613+ "SmallCaps should be expanded before normalization"
611inlineToMuse (Quoted SingleQuote lst) = do
614inlineToMuse (Quoted SingleQuote lst) = do
612 contents <- inlineListToMuse lst
615 contents <- inlineListToMuse lst
613 modify $ \st -> st { stUseTags = False }
616 modify $ \st -> st { stUseTags = False }
src/Text/Pandoc/Writers/OOXML.hs+7−3
@@ -25,6 +25,8 @@ module Text.Pandoc.Writers.OOXML ( mknode
25import Prelude
25import Prelude
26import Codec.Archive.Zip
26import Codec.Archive.Zip
27import Control.Monad.Reader
27import Control.Monad.Reader
28+import Control.Monad.Except (throwError)
29+import Text.Pandoc.Error
28import qualified Data.ByteString as B
30import qualified Data.ByteString as B
29import qualified Data.ByteString.Lazy as BL
31import qualified Data.ByteString.Lazy as BL
30import qualified Data.ByteString.Lazy.Char8 as BL8
32import qualified Data.ByteString.Lazy.Char8 as BL8
@@ -50,13 +52,15 @@ renderXml :: Element -> BL.ByteString
50renderXml elt = BL8.pack "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" <>
52renderXml elt = BL8.pack "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" <>
51 UTF8.fromStringLazy (showElement elt)
53 UTF8.fromStringLazy (showElement elt)
52
54
53−parseXml :: (PandocMonad m) => Archive -> Archive -> String -> m Element
55+parseXml :: PandocMonad m => Archive -> Archive -> String -> m Element
54parseXml refArchive distArchive relpath =
56parseXml refArchive distArchive relpath =
55 case findEntryByPath relpath refArchive `mplus`
57 case findEntryByPath relpath refArchive `mplus`
56 findEntryByPath relpath distArchive of
58 findEntryByPath relpath distArchive of
59+ Nothing -> throwError $ PandocSomeError $
57− Nothing -> Prelude.fail $ relpath ++ " missing in reference file"
60+ relpath ++ " missing in reference file"
58 Just e -> case parseXMLDoc . UTF8.toStringLazy . fromEntry $ e of
61 Just e -> case parseXMLDoc . UTF8.toStringLazy . fromEntry $ e of
62+ Nothing -> throwError $ PandocSomeError $
59− Nothing -> Prelude.fail $ relpath ++ " corrupt in reference file"
63+ relpath ++ " corrupt in reference file"
60 Just d -> return d
64 Just d -> return d
61
65
62-- Copied from Util
66-- Copied from Util