Skip to content

Commit

Permalink
Add new functions from GHC 9.12 to Effectful.Exception (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
arybczak authored Oct 22, 2024
1 parent eda264f commit b0a2f15
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions effectful-core/src/Effectful/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
module Effectful.Exception
( -- * Throwing
throwIO
#if MIN_VERSION_base(4,21,0)
, rethrowIO
#endif

-- * Catching (with recovery)
-- $catchAll
, catch
#if MIN_VERSION_base(4,21,0)
, catchNoPropagate
#endif
, catchDeep
, catchJust
, catchIf
Expand All @@ -29,6 +35,9 @@ module Effectful.Exception
, handleSyncDeep

, try
#if MIN_VERSION_base(4,21,0)
, tryWithContext
#endif
, tryDeep
, tryJust
, tryIf
Expand Down Expand Up @@ -93,6 +102,9 @@ module Effectful.Exception
, E.addExceptionContext
, E.someExceptionContext
, E.ExceptionWithContext(..)
#if MIN_VERSION_base(4,21,0)
, E.WhileHandling(..)
#endif
, E.ExceptionContext(..)
, E.emptyExceptionContext
, E.addExceptionAnnotation
Expand Down Expand Up @@ -158,6 +170,15 @@ throwIO
-> Eff es a
throwIO = unsafeEff_ . withFrozenCallStack E.throwIO

#if MIN_VERSION_base(4,21,0)
-- | Lifted 'E.rethrowIO'.
rethrowIO
:: E.Exception e
=> E.ExceptionWithContext e
-> Eff es a
rethrowIO = unsafeEff_ . E.rethrowIO
#endif

----------------------------------------
-- Catching

Expand Down Expand Up @@ -193,6 +214,18 @@ catchDeep
-> Eff es a
catchDeep action = catch (evaluateDeep =<< action)

#if MIN_VERSION_base(4,21,0)
-- | Lifted 'E.catchNoPropagate'.
catchNoPropagate
:: E.Exception e
=> Eff es a
-> (E.ExceptionWithContext e -> Eff es a)
-- ^ The exception handler.
-> Eff es a
catchNoPropagate action handler = reallyUnsafeUnliftIO $ \unlift -> do
E.catchNoPropagate (unlift action) (unlift . handler)
#endif

-- | Lifted 'E.catchJust'.
catchJust
:: E.Exception e
Expand Down Expand Up @@ -321,6 +354,16 @@ try
try action = reallyUnsafeUnliftIO $ \unlift -> do
E.try (unlift action)

#if MIN_VERSION_base(4,21,0)
-- | Lifted 'E.tryWithContext'.
tryWithContext
:: E.Exception e
=> Eff es a
-> Eff es (Either (E.ExceptionWithContext e) a)
tryWithContext action = reallyUnsafeUnliftIO $ \unlift -> do
E.tryWithContext (unlift action)
#endif

-- | A variant of 'try' that fully forces evaluation of the result value to find
-- all impure exceptions.
tryDeep
Expand Down

0 comments on commit b0a2f15

Please sign in to comment.