-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Pretty error messages for runtime invariants -- @package pretty-error @version 0.1.0.0 -- | Pretty runtime error messages -- -- These functions can be used to raise clear, understandable error -- messages for when your program violates an invariant at runtime. -- -- In particular, assertRight handles a common case where we -- "know" that a particular Either is going to be Right, -- and so we want to be able to unpack the value but also provide a -- high-quality error message if the value does somehow turn out to be a -- Left. module PrettyError -- | Assert that value is Right. Throw error if it's Left. -- -- The first argument is a message which can be used to explain why this -- error should not have happened. -- -- Use fromRight if you don't want to provide a message. -- --
-- >>> assertRight "Artificial example" (Right 5) -- 5 ---- --
-- >>> assertRight "Artificial example" (Left "error message") -- *** Exception: Artificial example: "error message" --assertRight :: Show a => Text -> Either a b -> b -- | Extract the value out of a Right, or throw an error from a -- Left made up of the pretty-printed Left value. -- -- Most of the time you should use assertRight, since that allows -- you to provide a message, which will help to debug the problem. -- --
-- >>> fromRight (Right 5) -- 5 ---- --
-- >>> fromRight (Left 4) -- *** Exception: 4 --fromRight :: Show a => Either a b -> b -- | Pretty print a variable to Text -- -- Although not strictly related to error messages, this is a handy -- function to have around if you are using Text.Show.Pretty and -- OverloadedStrings. ppText :: Show a => a -> Text -- | Raise an error with a pretty-printed value. -- --
-- >>> prettyError ["foo","bar","baz"] -- *** Exception: [ "foo" , "bar" , "baz" ] --prettyError :: Show a => a -> b