module B9.B9Error
( throwSomeException
, throwSomeException_
, throwB9Error
, throwB9Error_
, errorOnException
, ExcB9
, runExcB9
, B9Error(MkB9Error)
, fromB9Error
, catchB9Error
, catchB9ErrorAsEither
)
where
import Control.Exception ( toException
, SomeException
, Exception
, displayException
)
import Control.Eff as Eff
import Control.Eff.Exception as Eff
import Control.Monad
import Data.String ( IsString(..) )
type ExcB9 = Exc SomeException
newtype B9Error = MkB9Error { fromB9Error :: String }
deriving (Show, IsString)
instance Exception B9Error
runExcB9 :: Eff (ExcB9 ': e) a -> Eff e (Either SomeException a)
runExcB9 = runError
errorOnException :: Eff (ExcB9 ': e) a -> Eff e a
errorOnException = runError >=> either (error . displayException) pure
throwSomeException :: (Member ExcB9 e, Exception x) => x -> Eff e a
throwSomeException = throwError . toException
throwSomeException_ :: (Member ExcB9 e, Exception x) => x -> Eff e ()
throwSomeException_ = throwError_ . toException
throwB9Error :: Member ExcB9 e => String -> Eff e a
throwB9Error = throwSomeException . MkB9Error
throwB9Error_ :: Member ExcB9 e => String -> Eff e ()
throwB9Error_ = throwSomeException_ . MkB9Error
catchB9Error
:: Member ExcB9 e => Eff e a -> (SomeException -> Eff e a) -> Eff e a
catchB9Error = catchError
catchB9ErrorAsEither
:: Member ExcB9 e => Eff e a -> Eff e (Either SomeException a)
catchB9ErrorAsEither x = catchB9Error (Right <$> x) (pure . Left)