@@ -39,7 +39,6 @@ module Text.Pandoc.Class ( PandocMonad(..)
39 , addWarningWithPos
39 , addWarningWithPos
40 , PandocIO(..)
40 , PandocIO(..)
41 , PandocPure(..)
41 , PandocPure(..)
42− , PandocExecutionError(..)
43 , FileInfo(..)
42 , FileInfo(..)
45 , runIOorExplode
44 , runIOorExplode
@@ -83,12 +82,12 @@ import Control.Monad.State hiding (fail)
83import Control.Monad.Reader hiding (fail)
82import Control.Monad.Reader hiding (fail)
84import Control.Monad.Except hiding (fail)
83import Control.Monad.Except hiding (fail)
85import Data.Word (Word8)
84import Data.Word (Word8)
87import Data.Default
85import Data.Default
88import System.IO.Error
86import System.IO.Error
89import qualified Data.Map as M
87import qualified Data.Map as M
88+import Text.Pandoc.Error
91−class (Functor m, Applicative m, Monad m, MonadError PandocExecutionError m) => PandocMonad m where
90+class (Functor m, Applicative m, Monad m, MonadError PandocError m) => PandocMonad m where
92 lookupEnv :: String -> m (Maybe String)
91 lookupEnv :: String -> m (Maybe String)
93 getCurrentTime :: m UTCTime
92 getCurrentTime :: m UTCTime
94 getCurrentTimeZone :: m TimeZone
93 getCurrentTimeZone :: m TimeZone
@@ -143,12 +142,6 @@ addWarningWithPos mbpos msg =
144 msg ++ maybe "" (\pos -> " " ++ show pos) mbpos
143 msg ++ maybe "" (\pos -> " " ++ show pos) mbpos
146−-- We can add to this as we go
147−data PandocExecutionError = PandocFileReadError FilePath
148− | PandocShouldNeverHappenError String
149− | PandocParseError String
150− | PandocSomeError String
151− deriving (Show, Typeable)
153-- Nothing in this for now, but let's put it there anyway.
146-- Nothing in this for now, but let's put it there anyway.
154data PandocStateIO = PandocStateIO { ioStWarnings :: [String]
147data PandocStateIO = PandocStateIO { ioStWarnings :: [String]
@@ -168,35 +161,35 @@ instance Default PandocEnvIO where
168 , ioEnvOutputFile = Nothing -- stdout
161 , ioEnvOutputFile = Nothing -- stdout
171−runIO :: PandocIO a -> IO (Either PandocExecutionError a)
164+runIO :: PandocIO a -> IO (Either PandocError a)
172runIO ma = flip evalStateT def $ flip runReaderT def $ runExceptT $ unPandocIO ma
165runIO ma = flip evalStateT def $ flip runReaderT def $ runExceptT $ unPandocIO ma
174withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
167withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
175withMediaBag ma = ((,)) <$> ma <*> getMediaBag
168withMediaBag ma = ((,)) <$> ma <*> getMediaBag
177runIOorExplode :: PandocIO a -> IO a
170runIOorExplode :: PandocIO a -> IO a
178−runIOorExplode ma = do
171+runIOorExplode ma = handleError <$> runIO ma
179− eitherVal <- runIO ma
172+ -- eitherVal <- runIO ma
180− case eitherVal of
173+ -- case eitherVal of
181− Right x -> return x
174+ -- Right x -> return x
182− Left (PandocFileReadError fp) -> error $ "problem reading " ++ fp
175+ -- Left (PandocFileReadError fp) -> error $ "problem reading " ++ fp
183− Left (PandocShouldNeverHappenError s) -> error s
176+ -- Left (PandocShouldNeverHappenError s) -> error s
184− Left (PandocParseError s) -> error $ "parse error" ++ s
177+ -- Left (PandocParseError s) -> error $ "parse error" ++ s
185− Left (PandocSomeError s) -> error s
178+ -- Left (PandocSomeError s) -> error s
191newtype PandocIO a = PandocIO {
184newtype PandocIO a = PandocIO {
192− unPandocIO :: ExceptT PandocExecutionError (ReaderT PandocEnvIO (StateT PandocStateIO IO)) a
185+ unPandocIO :: ExceptT PandocError (ReaderT PandocEnvIO (StateT PandocStateIO IO)) a
193 } deriving ( MonadIO
186 } deriving ( MonadIO
194 , Functor
187 , Functor
195 , Applicative
188 , Applicative
197 , MonadReader PandocEnvIO
190 , MonadReader PandocEnvIO
198 , MonadState PandocStateIO
191 , MonadState PandocStateIO
199− , MonadError PandocExecutionError
192+ , MonadError PandocError
202instance PandocMonad PandocIO where
195instance PandocMonad PandocIO where
@@ -303,20 +296,18 @@ instance Default PureEnv where
303 , envOutputFile = Nothing
296 , envOutputFile = Nothing
306−instance E.Exception PandocExecutionError
308newtype PandocPure a = PandocPure {
299newtype PandocPure a = PandocPure {
309− unPandocPure :: ExceptT PandocExecutionError
300+ unPandocPure :: ExceptT PandocError
310 (ReaderT PureEnv (State PureState)) a
301 (ReaderT PureEnv (State PureState)) a
311 } deriving ( Functor
302 } deriving ( Functor
312 , Applicative
303 , Applicative
314 , MonadReader PureEnv
305 , MonadReader PureEnv
315 , MonadState PureState
306 , MonadState PureState
316− , MonadError PandocExecutionError
307+ , MonadError PandocError
319−runPure :: PandocPure a -> Either PandocExecutionError a
310+runPure :: PandocPure a -> Either PandocError a
320runPure x = flip evalState def $ flip runReaderT def $ runExceptT $ unPandocPure x
311runPure x = flip evalState def $ flip runReaderT def $ runExceptT $ unPandocPure x
322instance PandocMonad PandocPure where
313instance PandocMonad PandocPure where