module GHC.Types.SourceError
( SourceError (..)
, mkSrcErr
, srcErrorMessages
, throwErrors
, throwOneError
, handleSourceError
)
where
import GHC.Prelude
import GHC.Data.Bag
import GHC.Types.Error
import GHC.Utils.Monad
import GHC.Utils.Panic
import GHC.Utils.Exception
import Control.Monad.Catch as MC (MonadCatch, catch)
mkSrcErr :: ErrorMessages -> SourceError
mkSrcErr :: ErrorMessages -> SourceError
mkSrcErr = ErrorMessages -> SourceError
SourceError
srcErrorMessages :: SourceError -> ErrorMessages
srcErrorMessages :: SourceError -> ErrorMessages
srcErrorMessages (SourceError ErrorMessages
msgs) = ErrorMessages
msgs
throwErrors :: MonadIO io => ErrorMessages -> io a
throwErrors :: forall (io :: * -> *) a. MonadIO io => ErrorMessages -> io a
throwErrors = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Exception e => e -> IO a
throwIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorMessages -> SourceError
mkSrcErr
throwOneError :: MonadIO io => MsgEnvelope DecoratedSDoc -> io a
throwOneError :: forall (io :: * -> *) a.
MonadIO io =>
MsgEnvelope DecoratedSDoc -> io a
throwOneError = forall (io :: * -> *) a. MonadIO io => ErrorMessages -> io a
throwErrors forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Bag a
unitBag
newtype SourceError = SourceError ErrorMessages
instance Show SourceError where
show :: SourceError -> String
show (SourceError ErrorMessages
msgs) = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Bag a -> [a]
bagToList forall a b. (a -> b) -> a -> b
$ ErrorMessages
msgs
instance Exception SourceError
handleSourceError :: (MonadCatch m) =>
(SourceError -> m a)
-> m a
-> m a
handleSourceError :: forall (m :: * -> *) a.
MonadCatch m =>
(SourceError -> m a) -> m a -> m a
handleSourceError SourceError -> m a
handler m a
act =
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
MC.catch m a
act (\(SourceError
e :: SourceError) -> SourceError -> m a
handler SourceError
e)