{-# LANGUAGE FlexibleContexts #-}
module Futhark.Error
( CompilerError(..)
, ErrorClass(..)
, externalError
, externalErrorS
, InternalError
, internalError
, compilerBug
, compilerBugS
, compilerLimitation
, compilerLimitationS
)
where
import Control.Monad.Error.Class
import qualified Data.Text as T
data ErrorClass = CompilerBug
| CompilerLimitation
deriving (Eq, Ord, Show)
data CompilerError =
ExternalError T.Text
| InternalError T.Text T.Text ErrorClass
instance Show CompilerError where
show (ExternalError s) = T.unpack s
show (InternalError s _ _) = T.unpack s
externalError :: MonadError CompilerError m => T.Text -> m a
externalError = throwError . ExternalError
externalErrorS :: MonadError CompilerError m => String -> m a
externalErrorS = externalError . T.pack
data InternalError = Error ErrorClass T.Text
compilerBug :: MonadError InternalError m => T.Text -> m a
compilerBug = throwError . Error CompilerBug
compilerLimitation :: MonadError InternalError m => T.Text -> m a
compilerLimitation = throwError . Error CompilerLimitation
internalError :: MonadError CompilerError m => InternalError -> T.Text -> m a
internalError (Error c s) t = throwError $ InternalError s t c
compilerBugS :: MonadError InternalError m => String -> m a
compilerBugS = compilerBug . T.pack
compilerLimitationS :: MonadError InternalError m => String -> m a
compilerLimitationS = compilerLimitation . T.pack