@@ -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)
39type Input = String
40type Input = String
@@ -54,15 +55,15 @@ data PandocError = PandocFileReadError FilePath
55instance Exception PandocError
56instance Exception PandocError
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) ' '
76− in error $ "\nError at " ++ show err'
77+ in err 65 $ "\nError at " ++ show err' ++ errorInFile