@@ -35,6 +35,7 @@ import Text.Parsec.Error
3535import Text.Parsec.Pos hiding (Line)
3636import Data.Generics (Typeable)
3737import Control.Exception (Exception)
38+import Text.Pandoc.Shared (err)
3839
3940type Input = String
4041
@@ -54,15 +55,15 @@ data PandocError = PandocFileReadError FilePath
5455
5556instance Exception PandocError
5657
57−-- | An unsafe method to handle `PandocError`s.
58−handleError :: Either PandocError a -> a
59−handleError (Right r) = r
60−handleError (Left err) =
61− case err of
62− PandocFileReadError fp -> error $ "problem reading " ++ fp
63− PandocShouldNeverHappenError s -> error s
64− PandocSomeError s -> error s
65− PandocParseError s -> error s
58+-- | Handle PandocError by exiting with an error message.
59+handleError :: Either PandocError a -> IO a
60+handleError (Right r) = return r
61+handleError (Left e) =
62+ case e of
63+ PandocFileReadError fp -> err 61 $ "problem reading " ++ fp
64+ PandocShouldNeverHappenError s -> err 62 s
65+ PandocSomeError s -> err 63 s
66+ PandocParseError s -> err 64 s
6667 PandocParsecError input err' ->
6768 let errPos = errorPos err'
6869 errLine = sourceLine errPos
@@ -73,6 +74,5 @@ handleError (Left err) =
7374 ,"\n", replicate (errColumn - 1) ' '
7475 ,"^"]
7576 else ""
76− in error $ "\nError at " ++ show err'
77− ++ errorInFile
77+ in err 65 $ "\nError at " ++ show err' ++ errorInFile
7878