git.iko.soy/typeable/pandoc
on master help sign in
Error: change type of handleError.
d7583f3John MacFarlane
src/Text/Pandoc.hs+3−4
@@ -38,12 +38,11 @@ inline links:
38> module Main where
38> module Main where
39> import Text.Pandoc
39> import Text.Pandoc
40>
40>
41−> markdownToRST :: String -> String
41+> markdownToRST :: String -> Either PandocError String
42> markdownToRST =
42> markdownToRST =
43−> writeRST def {writerReferenceLinks = True} .
43+> writeRST def {writerReferenceLinks = True} . readMarkdown def
44−> handleError . readMarkdown def
45>
44>
46−> main = getContents >>= putStrLn . markdownToRST
45+> main = getContents >>= either error return markdownToRST >>= putStrLn
47
46
48Note: all of the readers assume that the input text has @'\n'@
47Note: all of the readers assume that the input text has @'\n'@
49line endings. So if you get your input text from a web form,
48line endings. So if you get your input text from a web form,
src/Text/Pandoc/Class.hs+1−1
@@ -190,7 +190,7 @@ withWarningsToStderr f = do
190 return x
190 return x
191
191
192runIOorExplode :: PandocIO a -> IO a
192runIOorExplode :: PandocIO a -> IO a
193−runIOorExplode ma = handleError <$> runIO ma
193+runIOorExplode ma = runIO ma >>= handleError
194
194
195newtype PandocIO a = PandocIO {
195newtype PandocIO a = PandocIO {
196 unPandocIO :: ExceptT PandocError (StateT CommonState IO) a
196 unPandocIO :: ExceptT PandocError (StateT CommonState IO) a
src/Text/Pandoc/Error.hs+11−11
@@ -35,6 +35,7 @@ import Text.Parsec.Error
35import Text.Parsec.Pos hiding (Line)
35import Text.Parsec.Pos hiding (Line)
36import Data.Generics (Typeable)
36import Data.Generics (Typeable)
37import Control.Exception (Exception)
37import Control.Exception (Exception)
38+import Text.Pandoc.Shared (err)
38
39
39type Input = String
40type Input = String
40
41
@@ -54,15 +55,15 @@ data PandocError = PandocFileReadError FilePath
54
55
55instance Exception PandocError
56instance Exception PandocError
56
57
57−-- | An unsafe method to handle `PandocError`s.
58+-- | Handle PandocError by exiting with an error message.
58−handleError :: Either PandocError a -> a
59+handleError :: Either PandocError a -> IO a
59−handleError (Right r) = r
60+handleError (Right r) = return r
60−handleError (Left err) =
61+handleError (Left e) =
61− case err of
62+ case e of
62− PandocFileReadError fp -> error $ "problem reading " ++ fp
63+ PandocFileReadError fp -> err 61 $ "problem reading " ++ fp
63− PandocShouldNeverHappenError s -> error s
64+ PandocShouldNeverHappenError s -> err 62 s
64− PandocSomeError s -> error s
65+ PandocSomeError s -> err 63 s
65− PandocParseError s -> error s
66+ PandocParseError s -> err 64 s
66 PandocParsecError input err' ->
67 PandocParsecError input err' ->
67 let errPos = errorPos err'
68 let errPos = errorPos err'
68 errLine = sourceLine errPos
69 errLine = sourceLine errPos
@@ -73,6 +74,5 @@ handleError (Left err) =
73 ,"\n", replicate (errColumn - 1) ' '
74 ,"\n", replicate (errColumn - 1) ' '
74 ,"^"]
75 ,"^"]
75 else ""
76 else ""
76− in error $ "\nError at " ++ show err'
77+ in err 65 $ "\nError at " ++ show err' ++ errorInFile
77− ++ errorInFile
78
78