Skip to content

Commit

Permalink
[#100] Add bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vrom911 committed Dec 21, 2017
1 parent 2584f36 commit 6ae961f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
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
24 changes: 24 additions & 0 deletions src/Universum/Exception.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE Safe #-}

Expand All @@ -7,6 +8,10 @@

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

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

#if ( __GLASGOW_HASKELL__ >= 800 )
import GHC.Show (Show)
import GHC.Stack (CallStack, HasCallStack)

import qualified Control.Exception.Safe as Safe (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

-- | 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 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 6ae961f

Please sign in to comment.