module GHC.Types.SourceError
( SourceError (..)
, mkSrcErr
, srcErrorMessages
, throwErrors
, throwOneError
, handleSourceError
)
where
import GHC.Prelude
import GHC.Types.Error
import GHC.Utils.Monad
import GHC.Utils.Panic
import GHC.Utils.Exception
import GHC.Utils.Error (pprMsgEnvelopeBagWithLocDefault)
import GHC.Utils.Outputable
import GHC.Driver.Errors.Ppr ()
import GHC.Driver.Errors.Types
import Control.Monad.Catch as MC (MonadCatch, catch)
mkSrcErr :: Messages GhcMessage -> SourceError
mkSrcErr :: Messages GhcMessage -> SourceError
mkSrcErr = Messages GhcMessage -> SourceError
SourceError
srcErrorMessages :: SourceError -> Messages GhcMessage
srcErrorMessages :: SourceError -> Messages GhcMessage
srcErrorMessages (SourceError Messages GhcMessage
msgs) = Messages GhcMessage
msgs
throwErrors :: MonadIO io => Messages GhcMessage -> io a
throwErrors :: forall (io :: * -> *) a. MonadIO io => Messages GhcMessage -> 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
. Messages GhcMessage -> SourceError
mkSrcErr
throwOneError :: MonadIO io => MsgEnvelope GhcMessage -> io a
throwOneError :: forall (io :: * -> *) a.
MonadIO io =>
MsgEnvelope GhcMessage -> io a
throwOneError = forall (io :: * -> *) a. MonadIO io => Messages GhcMessage -> io a
throwErrors forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. MsgEnvelope e -> Messages e
singleMessage
newtype SourceError = SourceError (Messages GhcMessage)
instance Show SourceError where
show :: SourceError -> String
show (SourceError Messages GhcMessage
msgs) =
SDocContext -> SDoc -> String
renderWithContext SDocContext
defaultSDocContext
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall doc. IsDoc doc => [doc] -> doc
vcat
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Diagnostic e => Bag (MsgEnvelope e) -> [SDoc]
pprMsgEnvelopeBagWithLocDefault
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Messages e -> Bag (MsgEnvelope e)
getMessages
forall a b. (a -> b) -> a -> b
$ Messages GhcMessage
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)