New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UnliftIO
variant
#6
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ module Control.Exception.Annotated | |
, checkpointCallStackWith | ||
-- * Handling Exceptions | ||
, catch | ||
, catches | ||
, tryAnnotated | ||
, try | ||
|
||
|
@@ -183,7 +184,7 @@ catch action handler = | |
-- | Like 'Safe.catches', but this function enhance the provided 'Handler's | ||
-- to "see through" any 'AnnotatedException's. | ||
-- | ||
-- @since 0.1.1.0 | ||
-- @since 0.1.2.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s i g h |
||
catches :: (MonadCatch m) => m a -> [Handler m a] -> m a | ||
catches action handlers = | ||
Safe.catches action (mkAnnotatedHandlers handlers) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
{-# language ExplicitForAll #-} | ||
|
||
-- | This module presents the same interface as | ||
-- "Control.Exception.Annotated", but uses 'MonadUnliftIO' instead of | ||
-- 'MonadCatch' or 'MonadThrow'. | ||
-- | ||
-- @since 0.1.2.0 | ||
module Control.Exception.Annotated.UnliftIO | ||
( -- * The Main Type | ||
AnnotatedException(..) | ||
, new | ||
, throwWithCallStack | ||
-- * Annotating Exceptions | ||
, checkpoint | ||
, checkpointMany | ||
, checkpointCallStack | ||
, checkpointCallStackWith | ||
-- * Handling Exceptions | ||
, catch | ||
, catches | ||
, tryAnnotated | ||
, try | ||
|
||
-- * Manipulating Annotated Exceptions | ||
, check | ||
, hide | ||
, annotatedExceptionCallStack | ||
, addCallStackToException | ||
|
||
-- * Re-exports from "Data.Annotation" | ||
, Annotation(..) | ||
, CallStackAnnotation(..) | ||
-- * Re-exports from "Control.Exception.Safe" | ||
, Exception(..) | ||
, Safe.SomeException(..) | ||
, throw | ||
, Handler (..) | ||
, MonadIO(..) | ||
, MonadUnliftIO(..) | ||
) where | ||
|
||
import Control.Exception.Annotated hiding | ||
( catch | ||
, catches | ||
, checkpoint | ||
, checkpointCallStackWith | ||
, checkpointMany | ||
, throw | ||
, throwWithCallStack | ||
, try | ||
, tryAnnotated | ||
) | ||
import qualified Control.Exception.Annotated as Catch | ||
import qualified Control.Exception.Safe as Safe | ||
import Control.Monad.IO.Unlift | ||
import GHC.Stack | ||
|
||
-- | Like 'Catch.throwWithCallStack', but uses 'MonadIO' instead of | ||
-- 'MonadThrow'. | ||
-- | ||
-- @since 0.1.2.0 | ||
throwWithCallStack | ||
:: forall e m a. (MonadIO m, Exception e, HasCallStack) | ||
=> e -> m a | ||
throwWithCallStack = liftIO . Catch.throwWithCallStack | ||
|
||
-- | Like 'Catch.throw', but uses 'MonadIO' instead of 'MonadThrow'. | ||
-- | ||
-- @since 0.1.2.0 | ||
throw :: forall e m a. (MonadIO m, Exception e) => e -> m a | ||
throw = liftIO . Catch.throw | ||
|
||
-- | Like 'Catch.checkpoint', but uses 'MonadUnliftIO' instead of 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
checkpoint :: forall m a. (MonadUnliftIO m) => Annotation -> m a -> m a | ||
checkpoint ann action = withRunInIO $ \runInIO -> | ||
liftIO $ Catch.checkpoint ann (runInIO action) | ||
|
||
-- | Like 'Catch.checkpointMany', but uses 'MonadUnliftIO' instead of | ||
-- 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
checkpointMany :: forall m a. (MonadUnliftIO m) => [Annotation] -> m a -> m a | ||
checkpointMany anns action = | ||
withRunInIO $ \runInIO -> | ||
liftIO $ Catch.checkpointMany anns (runInIO action) | ||
Comment on lines
+86
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. b o r i n g |
||
|
||
-- | Like 'Catch.checkpointCallStackWith', but uses 'MonadUnliftIO' instead of | ||
-- 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
checkpointCallStackWith | ||
:: forall m a. (MonadUnliftIO m, HasCallStack) | ||
=> [Annotation] -> m a -> m a | ||
checkpointCallStackWith anns action = | ||
withRunInIO $ \runInIO -> | ||
liftIO $ Catch.checkpointCallStackWith anns (runInIO action) | ||
|
||
-- | Like 'Catch.catch', but uses 'MonadUnliftIO' instead of 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
catch | ||
:: forall e m a. (MonadUnliftIO m, Exception e) | ||
=> m a | ||
-> (e -> m a) | ||
-> m a | ||
catch action handler = | ||
withRunInIO $ \runInIO -> | ||
liftIO $ Catch.catch (runInIO action) (\e -> runInIO $ handler e) | ||
|
||
-- | Like 'Catch.tryAnnotated' but uses 'MonadUnliftIO' instead of 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
tryAnnotated | ||
:: forall e m a. (MonadUnliftIO m, Exception e) | ||
=> m a | ||
-> m (Either (AnnotatedException e) a) | ||
tryAnnotated action = | ||
withRunInIO $ \runInIO -> | ||
liftIO $ Catch.tryAnnotated (runInIO action) | ||
|
||
-- | Like 'Catch.try' but uses 'MonadUnliftIO' instead of 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
try | ||
:: forall e m a. (MonadUnliftIO m, Exception e) | ||
=> m a | ||
-> m (Either e a) | ||
try action = | ||
withRunInIO $ \runInIO -> | ||
liftIO $ Catch.try (runInIO action) | ||
|
||
-- | Like 'Catch.catches', bt uses 'MonadUnliftIO' instead of 'MonadCatch'. | ||
-- | ||
-- @since 0.1.2.0 | ||
catches | ||
:: forall m a. MonadUnliftIO m | ||
=> m a | ||
-> [Handler m a] | ||
-> m a | ||
catches action handlers = | ||
withRunInIO $ \runInIO -> do | ||
let f (Handler k) = Handler (\e -> runInIO (k e)) | ||
liftIO $ catches (runInIO action) (map f handlers) | ||
where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmao