error-list-0.1.0.0: A useful type for collecting error messages.

Safe HaskellNone
LanguageHaskell2010

Control.Exception.ErrorList

Synopsis

Documentation

class IsList elist => ErrorList elist where Source

Methods

addError :: Text -> elist -> elist Source

oneError :: Text -> elist Source

throwError1 :: (ErrorList e, MonadError e m) => Text -> m a Source

Throws a single-message eror list.

throwErrorC :: (ErrorList e, MonadError e m) => [Text] -> m a Source

Concatenates a list of strings and throws them as an error.

addError1 :: (ErrorList e, MonadError e m) => Text -> e -> m a Source

Throws a new error with the given string added on.

addErrorC :: (ErrorList e, MonadError e m) => [Text] -> e -> m a Source

Throws a new error with the concatenation of the argument added on.

assert :: (ErrorList e, MonadError e m) => Bool -> Text -> m () Source

If the test is false, throws an error with the given message.

assertC :: (ErrorList e, MonadError e m) => Bool -> [Text] -> m () Source

Same as assert, but concatenates a text list.

wrapJust :: MonadError e m => m a -> m (Maybe a) Source

Wraps a successful result in a Just and a failure in a Nothing.

withHandler :: MonadError e m => (e -> m a) -> m a -> m a Source

Useful when the handler is more concise than the action.

ifErrorDo :: MonadError e m => m a -> m a -> m a Source

Specifies what to do if the given action fails.

ifErrorReturn :: MonadError e m => m a -> a -> m a Source

Performs an action, returning the second argument if it fails.

showError :: (Render e, Render b) => (a -> Either e b) -> a -> IO () Source

Pretty-prints errors that use Either.

showError' :: (Render e, Render b) => (a -> (Either e b, c)) -> a -> IO () Source

Pretty-prints errors that use Either, appearing in tuples.

errorC :: [Text] -> a Source

Concatenates a list of Text and makes an error out of it.

oneErrorC :: ErrorList e => [Text] -> e Source

Pretty-prints an error list. Considers the first item of the list to be the "main" message; subsequent messages are listed after. printErrors :: ErrorList e => e -> IO () printErrors (ErrorList err errs) = do P.putStrLn ("Error: " <> unpack err) P.mapM_ (P.putStrLn . unpack . (" " <>)) errs

Same as oneError but concatenates its argument.

firstSuccess :: (ErrorList e, MonadError e m) => Text -> [m a] -> m a Source

inContext :: (ErrorList e, MonadError e m) => Text -> m a -> m a Source

Tries something and throws an error if it fails.