-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | The canonical error type -- -- A canonical Error type, which provides a way to turn an error -- string into an Error, add context to an Error, and -- pretty print the Error for displaying it to users. @package error @version 0.1.1.0 module Data.Error -- | The canonical Error type. -- -- It can be -- --
-- addContext "Trying to open config file" -- $ newError "file not found: ./foo" ---- -- This way, when a user see the error, they will understand better what -- happened: -- --
-- "Trying to open config file: file not found: ./foo" ---- -- See prettyError. addContext :: Text -> Error -> Error -- | Pretty print the error. -- -- It will print all context messages, starting with the outermost. -- -- Example: -- --
-- >>> prettyError $ newError "file not found: ./foo" -- "file not found: ./foo" ---- --
-- >>> :{
-- prettyError
-- $ addContext "Trying to open config file"
-- $ newError "file not found: ./foo"
-- :}
-- "Trying to open config file: file not found: ./foo"
--
prettyError :: Error -> Text
-- | Return the value from a potentially failing computation.
--
-- Abort with the error message if it was an error.
--
-- The text message is added to the Error as additional context
-- before aborting.
--
-- Panics: if Error
--
-- Example:
--
-- -- >>> expectError "something bad happened" $ Left (newError "oh no!") -- *** Exception: something bad happened: oh no! -- ... ---- --
-- >>> expectError "something bad happened" $ Right 42 -- 42 --expectError :: HasCallStack => Text -> Either Error p -> p -- | Return the value from a potentially failing computation. -- -- Abort with the Errors message if it was a Left. -- -- Panics: if Error -- -- Example: -- --
-- >>> unwrapError $ Left (newError "oh no!") -- *** Exception: oh no! -- ... ---- --
-- >>> unwrapError $ Right 42 -- 42 --unwrapError :: HasCallStack => Either Error p -> p