Skip to content

Commit

Permalink
Merge pull request #103 from serokell/vrom911/100-bug
Browse files Browse the repository at this point in the history
[#100] Add bug
  • Loading branch information
vrom911 authored Dec 22, 2017
2 parents 2584f36 + 4dda527 commit ed9c424
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.1
=====

* [#100](https:/serokell/universum/issues/100):
Add `bug` function = `impureThrow`.

1.0.0
=====

Expand Down
2 changes: 1 addition & 1 deletion src/Universum/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import Data.Typeable (Typeable)
import Data.Void (Void, absurd, vacuous)
#endif

import GHC.Base (String, asTypeOf, maxInt, minInt, ord, seq, (++))
import GHC.Base (String, asTypeOf, maxInt, minInt, ord, seq)
import GHC.Enum (Bounded (..), Enum (..), boundedEnumFrom, boundedEnumFromThen)
import GHC.Exts (Constraint, FunPtr, Ptr)
import GHC.Float (Double (..), Float (..), Floating (..))
Expand Down
26 changes: 26 additions & 0 deletions src/Universum/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

module Universum.Exception
( module Control.Exception.Safe
#if ( __GLASGOW_HASKELL__ >= 800 )
, Bug (..)
, bug
#endif
, note
) where

Expand All @@ -19,6 +23,28 @@ import Control.Applicative (Applicative (pure))
import Control.Monad.Except (MonadError, throwError)
import Data.Maybe (Maybe, maybe)

#if ( __GLASGOW_HASKELL__ >= 800 )
import Data.List ((++))
import GHC.Show (Show)
import GHC.Stack (CallStack, HasCallStack, callStack, prettyCallStack)

import qualified Control.Exception.Safe as Safe (displayException, impureThrow, toException)

-- | Type that represents exceptions used in cases when a particular codepath
-- is not meant to be ever executed, but happens to be executed anyway.
data Bug = Bug SomeException CallStack
deriving (Show)

instance Exception Bug where
displayException (Bug e cStack) = Safe.displayException e ++ "\n"
++ prettyCallStack cStack

-- | Generate a pure value which, when forced, will synchronously
-- throw the exception wrapped into 'Bug' data type.
bug :: (HasCallStack, Exception e) => e -> a
bug e = Safe.impureThrow (Bug (Safe.toException e) callStack)
#endif

-- To suppress redundant applicative constraint warning on GHC 8.0
-- | Throws error for 'Maybe' if 'Data.Maybe.Nothing' is given.
-- Operates over 'MonadError'.
Expand Down
2 changes: 1 addition & 1 deletion src/Universum/List/Reexport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Data.List (break, cycle, drop, dropWhile, filter, genericDrop, genericLen
genericReplicate, genericSplitAt, genericTake, group, inits, intercalate,
intersperse, isPrefixOf, iterate, permutations, repeat, replicate, reverse, scanl,
scanr, sort, sortBy, sortOn, splitAt, subsequences, tails, take, takeWhile,
transpose, unfoldr, unzip, unzip3, zip, zip3, zipWith)
transpose, unfoldr, unzip, unzip3, zip, zip3, zipWith, (++))

#if ( __GLASGOW_HASKELL__ >= 800 )
import Data.List.NonEmpty (head, init, last, tail)
Expand Down
2 changes: 1 addition & 1 deletion universum.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: universum
version: 1.0.0
version: 1.0.1
synopsis: Custom prelude used in Serokell
description: Custom prelude used in Serokell
homepage: https:/serokell/universum
Expand Down

0 comments on commit ed9c424

Please sign in to comment.