Skip to content

Commit

Permalink
[kowainik#9] Remove safe-exceptions (kowainik#25)
Browse files Browse the repository at this point in the history
* [kowainik#9] Remove safe-exceptions

* Add copyrights to Exceptions module
  • Loading branch information
vrom911 authored Jul 20, 2018
1 parent 4c37060 commit 8e35d22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ Change log
Remove `liquid-haskell` support.
* [#10](https://github.com/kowainik/universum/issues/10):
Remove `Universum.VarArg` module.
* [#9](https://github.com/kowainik/universum/issues/9):
Remove `safe-exceptions` from dependencies. Reexport `Exception` and
`SomeException` from `Control.Exception` instead.

universum uses [PVP Versioning][1].

`universum` uses [PVP Versioning][1].
The change log is available [on GitHub][2].

[1]: https://pvp.haskell.org
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ We also have `data Undefined = Undefined` (which, too, comes with warnings).

### Exceptions

We use [`safe-exceptions`](https://github.com/fpco/safe-exceptions)
library for exceptions handling. Don't import `Control.Exceptions`
module explicitly. Instead use functionality from `safe-exceptions`
provided by `universum` or import `Control.Exceptions.Safe` module.
TODO: write about reexports, `Bug` and `Exc` pattern.

What's new? [](#structure-of-this-tutorial)
-----------
Expand Down
27 changes: 18 additions & 9 deletions src/Universum/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE ViewPatterns #-}

{-
Copyright: (c) 2016 Stephen Diehl
(c) 20016-2018 Serokell
(c) 2018 Kowainik
License: MIT
-}

-- | Re-exports most useful functionality from 'safe-exceptions'. Also
-- provides some functions to work with exceptions over 'MonadError'.

module Universum.Exception
( module Control.Exception.Safe
( module Control.Exception
#if ( __GLASGOW_HASKELL__ >= 800 )
, Bug (..)
, bug
Expand All @@ -17,11 +24,7 @@ module Universum.Exception
, note
) where

-- exceptions from safe-exceptions
import Control.Exception.Safe (Exception (..), MonadCatch, MonadMask (..), MonadThrow,
SomeException (..), bracket, bracketOnError, bracket_, catch,
catchAny, displayException, finally, handleAny, mask_, onException,
throwM, try, tryAny)
import Control.Exception (Exception (..), SomeException (..))

import Control.Monad.Except (MonadError, throwError)
import Universum.Applicative (Applicative (pure))
Expand All @@ -32,21 +35,27 @@ import Data.List ((++))
import GHC.Show (Show)
import GHC.Stack (CallStack, HasCallStack, callStack, prettyCallStack)

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

import qualified Control.Exception as E (displayException, throw, 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"
displayException (Bug e cStack) = E.displayException e ++ "\n"
++ prettyCallStack cStack

-- | Generate a pure value which, when forced, will throw the given exception
impureThrow :: Exception e => e -> a
impureThrow = E.throw . E.toException

-- | 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)
bug e = impureThrow (Bug (E.toException e) callStack)
#endif

-- To suppress redundant applicative constraint warning on GHC 8.0
Expand Down
1 change: 0 additions & 1 deletion universum.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ library
, ghc-prim >= 0.4.0.0
, hashable
, mtl
, safe-exceptions
, stm
, text
, transformers
Expand Down

0 comments on commit 8e35d22

Please sign in to comment.