| Copyright | (c) Moritz Clasmeier 2018 |
|---|---|
| License | BSD3 |
| Maintainer | mtesseract@silverratio.net |
| Stability | experimental |
| Portability | POSIX |
| Safe Haskell | None |
| Language | Haskell2010 |
Control.Error.Context
Description
Provides an API for enriching errors with contexts.
- data ErrorContext = ErrorContext [Text]
- data ErrorContextT m a
- class (Monad m, MonadThrow m) => MonadErrorContext m where
- data ErrorWithContext e = ErrorWithContext ErrorContext e
- runErrorContextT :: ErrorContextT m a -> m a
- errorContextualize :: MonadErrorContext m => e -> m (ErrorWithContext e)
- errorContextForget :: ErrorWithContext e -> e
- errorWithContextDump :: (Show e, MonadIO m) => ErrorWithContext e -> m ()
- catchWithoutContext :: forall a e m. (MonadCatch m, Exception e) => m a -> (e -> m a) -> m a
- catchWithContext :: (MonadCatch m, Exception e) => m a -> (ErrorWithContext e -> m a) -> m a
- catchAnyWithContext :: MonadCatch m => m a -> (ErrorWithContext SomeException -> m a) -> m a
- ensureExceptionContext :: (MonadCatch m, MonadErrorContext m) => m a -> m a
- tryAnyWithContext :: MonadCatch m => m a -> m (Either (ErrorWithContext SomeException) a)
- tryAnyWithoutContext :: MonadCatch m => m a -> m (Either SomeException a)
- tryWithContext :: (MonadCatch m, Exception e) => m a -> m (Either (ErrorWithContext e) a)
- tryWithoutContext :: (MonadCatch m, Exception e) => m a -> m (Either e a)
Documentation
data ErrorContext Source #
Encapsulates the error context — essentially a stack of Text
values.
Constructors
| ErrorContext [Text] |
Instances
data ErrorContextT m a Source #
Data type implementing MonadErrorContext.
Instances
| MonadTrans ErrorContextT Source # | |
| MonadWriter w m => MonadWriter w (ErrorContextT m) Source # | |
| MonadState s m => MonadState s (ErrorContextT m) Source # | |
| MonadReader r m => MonadReader r (ErrorContextT m) Source # | Implement |
| Monad m => Monad (ErrorContextT m) Source # | |
| Functor m => Functor (ErrorContextT m) Source # | |
| Applicative m => Applicative (ErrorContextT m) Source # | |
| (MonadCatch m, MonadIO m) => MonadIO (ErrorContextT m) Source # | |
| (MonadCatch m, MonadResource m) => MonadResource (ErrorContextT m) Source # | Implement |
| MonadThrow m => MonadThrow (ErrorContextT m) Source # | Implement |
| MonadCatch m => MonadCatch (ErrorContextT m) Source # | Implement |
| MonadThrow m => MonadErrorContext (ErrorContextT m) Source # | Implement |
class (Monad m, MonadThrow m) => MonadErrorContext m where Source #
Monad type class providing contextualized errors.
Minimal complete definition
Methods
Arguments
| :: m ErrorContext | Return the current error context. |
Instances
| MonadThrow m => MonadErrorContext (ErrorContextT m) Source # | Implement |
data ErrorWithContext e Source #
Boundles an error with an ErrorContext.
Constructors
| ErrorWithContext ErrorContext e |
Instances
| Functor ErrorWithContext Source # | |
| Show e => Show (ErrorWithContext e) Source # | |
| Exception e => Exception (ErrorWithContext e) Source # | An |
runErrorContextT :: ErrorContextT m a -> m a Source #
Unwrap an ErrorContextT. Exceptions of type e thrown in the
provided action via throwM will cause an
exception to be propagated upwards.ErrorWithContext e
errorContextualize :: MonadErrorContext m => e -> m (ErrorWithContext e) Source #
Enrich an error value with an error context.
errorContextForget :: ErrorWithContext e -> e Source #
Forgets the context from an enriched error.
errorWithContextDump :: (Show e, MonadIO m) => ErrorWithContext e -> m () Source #
Dump an error with context to stdout.
catchWithoutContext :: forall a e m. (MonadCatch m, Exception e) => m a -> (e -> m a) -> m a Source #
Like catch, but the handler is required to be context-unaware.
Is also able to catch exceptions with context, in which case the
context will be forgotten before the exception will be provided to
the handler.
catchWithContext :: (MonadCatch m, Exception e) => m a -> (ErrorWithContext e -> m a) -> m a Source #
Like catch, but the handler is required to be context-aware. Is
also able to catch exceptions of type e (without context).
catchAnyWithContext :: MonadCatch m => m a -> (ErrorWithContext SomeException -> m a) -> m a Source #
Context aware version of catchAny.
ensureExceptionContext :: (MonadCatch m, MonadErrorContext m) => m a -> m a Source #
tryAnyWithContext :: MonadCatch m => m a -> m (Either (ErrorWithContext SomeException) a) Source #
tryAnyWithoutContext :: MonadCatch m => m a -> m (Either SomeException a) Source #
tryWithContext :: (MonadCatch m, Exception e) => m a -> m (Either (ErrorWithContext e) a) Source #
tryWithoutContext :: (MonadCatch m, Exception e) => m a -> m (Either e a) Source #