Safe Haskell | None |
---|---|

Language | Haskell2010 |

Provides composable and hierarchical errors, with pretty
printing. The errors are accumulated in a tree like structure,
`ErrorAcc`

. `ErrorAcc`

is disigned to be read by humans, via
`prettyErrAcc`

, not dispatched on by code. Using `toE`

to convert an
`ErrorOr`

to IO throws (in case it holds an error) a `PrettyErrAcc`

that uses `pretty`

in the show instance.

## Synopsis

- newtype ErrorOr a = ErrorOr {}
- tag :: Text -> ErrorOr a -> ErrorOr a
- pattern Error :: ErrorAcc -> ErrorOr a
- pattern OK :: a -> ErrorOr a
- isOK :: ErrorOr a -> Bool
- isError :: ErrorOr a -> Bool
- fromOK :: ErrorOr a -> a
- failText :: Text -> ErrorOr a
- class ErrorConv t s where
- toE :: t a -> s a

- data ErrorAcc
- prettyErrAcc :: Int -> ErrorAcc -> Text
- newtype PrettyErrAcc = PrettyErrAcc {}
- tagIO :: Text -> IO a -> IO a

# Documentation

Use `Applicative`

's `sequenceA`

and `sequenceA_`

to compose `ErrorOr`

s as opposed to `Monad`

derived functions like `sequence`

.

#### Instances

Monad ErrorOr Source # | OrError's instances for |

Functor ErrorOr Source # | |

MonadFail ErrorOr Source # | |

Defined in Data.ErrorOr | |

Applicative ErrorOr Source # | |

Foldable ErrorOr Source # | |

Defined in Data.ErrorOr fold :: Monoid m => ErrorOr m -> m # foldMap :: Monoid m => (a -> m) -> ErrorOr a -> m # foldMap' :: Monoid m => (a -> m) -> ErrorOr a -> m # foldr :: (a -> b -> b) -> b -> ErrorOr a -> b # foldr' :: (a -> b -> b) -> b -> ErrorOr a -> b # foldl :: (b -> a -> b) -> b -> ErrorOr a -> b # foldl' :: (b -> a -> b) -> b -> ErrorOr a -> b # foldr1 :: (a -> a -> a) -> ErrorOr a -> a # foldl1 :: (a -> a -> a) -> ErrorOr a -> a # elem :: Eq a => a -> ErrorOr a -> Bool # maximum :: Ord a => ErrorOr a -> a # minimum :: Ord a => ErrorOr a -> a # | |

Traversable ErrorOr Source # | |

MonadError ErrorAcc ErrorOr Source # | |

Defined in Data.ErrorOr throwError :: ErrorAcc -> ErrorOr a # catchError :: ErrorOr a -> (ErrorAcc -> ErrorOr a) -> ErrorOr a # | |

ErrorConv Maybe ErrorOr Source # | Convert from 'Maybe a' to 'ErrorOr a'. It converts |

ErrorConv ErrorOr IO Source # | Convert from ErrorOr to IO. |

Eq a => Eq (ErrorOr a) Source # | |

Ord a => Ord (ErrorOr a) Source # | |

Defined in Data.ErrorOr | |

Read a => Read (ErrorOr a) Source # | |

Show a => Show (ErrorOr a) Source # | |

Semigroup a => Semigroup (ErrorOr a) Source # | |

(Semigroup (ErrorOr a), Monoid a) => Monoid (ErrorOr a) Source # | |

Show e => ErrorConv (Either e) ErrorOr Source # | Convert from `Either e`, |

class ErrorConv t s where Source #

Convert between functors that hold error info.

#### Instances

ErrorConv Maybe ErrorOr Source # | Convert from 'Maybe a' to 'ErrorOr a'. It converts |

ErrorConv ErrorOr IO Source # | Convert from ErrorOr to IO. |

Show e => ErrorConv (Either e) ErrorOr Source # | Convert from `Either e`, |

#### Instances

Eq ErrorAcc Source # | |

Ord ErrorAcc Source # | |

Defined in Data.ErrorOr | |

Read ErrorAcc Source # | |

Show ErrorAcc Source # | |

IsString ErrorAcc Source # | |

Defined in Data.ErrorOr fromString :: String -> ErrorAcc # | |

Semigroup ErrorAcc Source # | |

MonadError ErrorAcc ErrorOr Source # | |

Defined in Data.ErrorOr throwError :: ErrorAcc -> ErrorOr a # catchError :: ErrorOr a -> (ErrorAcc -> ErrorOr a) -> ErrorOr a # |

newtype PrettyErrAcc Source #

A wrapper over `ErrorAcc`

to provide human readable exceptions.
(Exception class' displayException does not seem to be used by GHC)
https://stackoverflow.com/questions/55490766/why-doesn-t-ghc-use-my-displayexception-method

#### Instances

Show PrettyErrAcc Source # | |

Defined in Data.ErrorOr showsPrec :: Int -> PrettyErrAcc -> ShowS # show :: PrettyErrAcc -> String # showList :: [PrettyErrAcc] -> ShowS # | |

Exception PrettyErrAcc Source # | |

Defined in Data.ErrorOr |

tagIO :: Text -> IO a -> IO a Source #

Tag an exception with an annotation.

It acts on two types of exceptions: `IOException`

and
`PrettyErrAcc`

. For `PrettyErrAcc`

it is streightforward tagging.
For `IOException`

, otoh, it converts the error message into Text
via String and turns it into `PrettyErrAcc`

tagged with provided
adnotation.

This is rather a convenience function. Sometimes it is convenient
to `fail "msg"`

in IO, and tag it higher up with some context. The
need for `tagIO`

often comes with `lookup`

(from
error-or-utils package) when used from IO, which is overloaded for
MonadFail.

Since ver 0.1.1.0