universum-1.2.0: Custom prelude used in Serokell

Safe HaskellSafe



Re-exports most useful functionality from 'safe-exceptions'. Also provides some functions to work with exceptions over MonadError.



data Bug Source #

Type that represents exceptions used in cases when a particular codepath is not meant to be ever executed, but happens to be executed anyway.

bug :: (HasCallStack, Exception e) => e -> a Source #

Generate a pure value which, when forced, will synchronously throw the exception wrapped into Bug data type.

pattern Exc :: Exception e => e -> SomeException Source #

Pattern synonym to easy pattern matching on exceptions. So intead of writing something like this:

isNonCriticalExc e
    | Just (_ :: NodeAttackedError) <- fromException e = True
    | Just DialogUnexpected{} <- fromException e = True
    | otherwise = False

you can use Exc pattern synonym:

isNonCriticalExc = case
    Exc (_ :: NodeAttackedError) -> True  -- matching all exceptions of type NodeAttackedError
    Exc DialogUnexpected{} -> True
    _ -> False

This pattern is bidirectional. You can use Exc e instead of toException e.

note :: MonadError e m => e -> Maybe a -> m a Source #

Throws error for Maybe if Nothing is given. Operates over MonadError.