module Incipit.Exception where
import qualified Control.Exception as Base
import Control.Exception (Exception, SomeException)
import Data.Bifunctor (first)
import Data.Either (Either)
import Data.Function ((.))
import Data.Functor (fmap, void)
import Data.Maybe (Maybe)
import Polysemy (Embed, Member, Sem, embed)
import System.IO (IO)
import System.IO.Error (IOError)
import Incipit.Either (rightToMaybe)
import Incipit.String.Conversion (show)
import Incipit.String.Reexport (Text)
tryIOE ::
∀ e r a .
Exception e =>
Member (Embed IO) r =>
IO a ->
Sem r (Either e a)
tryIOE :: forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either e a)
tryIOE =
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed @IO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Exception e => IO a -> IO (Either e a)
Base.try @e
{-# inline tryIOE #-}
tryIO ::
∀ e r a .
Exception e =>
Member (Embed IO) r =>
IO a ->
Sem r (Either Text a)
tryIO :: forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO =
forall (m :: * -> *) (r :: EffectRow) a.
Member (Embed m) r =>
m a -> Sem r a
embed @IO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall b a. (Show a, IsString b) => a -> b
show) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e a. Exception e => IO a -> IO (Either e a)
Base.try @e
{-# inline tryIO #-}
tryIOError ::
∀ r a .
Member (Embed IO) r =>
IO a ->
Sem r (Either Text a)
tryIOError :: forall (r :: EffectRow) a.
Member (Embed IO) r =>
IO a -> Sem r (Either Text a)
tryIOError =
forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO @IOError
{-# inline tryIOError #-}
tryAny ::
∀ r a .
Member (Embed IO) r =>
IO a ->
Sem r (Either Text a)
tryAny :: forall (r :: EffectRow) a.
Member (Embed IO) r =>
IO a -> Sem r (Either Text a)
tryAny =
forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO @SomeException
{-# inline tryAny #-}
tryIOMaybe ::
∀ e r a .
Exception e =>
Member (Embed IO) r =>
IO a ->
Sem r (Maybe a)
tryIOMaybe :: forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Maybe a)
tryIOMaybe =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall l r. Either l r -> Maybe r
rightToMaybe forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO @e
{-# inline tryIOMaybe #-}
tryIOErrorMaybe ::
∀ r a .
Member (Embed IO) r =>
IO a ->
Sem r (Maybe a)
tryIOErrorMaybe :: forall (r :: EffectRow) a.
Member (Embed IO) r =>
IO a -> Sem r (Maybe a)
tryIOErrorMaybe =
forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Maybe a)
tryIOMaybe @IOError
{-# inline tryIOErrorMaybe #-}
tryMaybe ::
∀ r a .
Member (Embed IO) r =>
IO a ->
Sem r (Maybe a)
tryMaybe :: forall (r :: EffectRow) a.
Member (Embed IO) r =>
IO a -> Sem r (Maybe a)
tryMaybe =
forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Maybe a)
tryIOMaybe @SomeException
{-# inline tryMaybe #-}
tryIO_ ::
∀ e r .
Exception e =>
Member (Embed IO) r =>
IO () ->
Sem r ()
tryIO_ :: forall e (r :: EffectRow).
(Exception e, Member (Embed IO) r) =>
IO () -> Sem r ()
tryIO_ =
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO @e
{-# inline tryIO_ #-}
tryIOError_ ::
∀ r .
Member (Embed IO) r =>
IO () ->
Sem r ()
tryIOError_ :: forall (r :: EffectRow). Member (Embed IO) r => IO () -> Sem r ()
tryIOError_ =
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO @IOError
{-# inline tryIOError_ #-}
tryAny_ ::
∀ r .
Member (Embed IO) r =>
IO () ->
Sem r ()
tryAny_ :: forall (r :: EffectRow). Member (Embed IO) r => IO () -> Sem r ()
tryAny_ =
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (r :: EffectRow) a.
(Exception e, Member (Embed IO) r) =>
IO a -> Sem r (Either Text a)
tryIO @SomeException
{-# inline tryAny_ #-}
ignoreException ::
Member (Embed IO) r =>
IO () ->
Sem r ()
ignoreException :: forall (r :: EffectRow). Member (Embed IO) r => IO () -> Sem r ()
ignoreException =
forall (r :: EffectRow). Member (Embed IO) r => IO () -> Sem r ()
tryAny_
{-# inline ignoreException #-}
{-# deprecated ignoreException "renamed to 'tryAny_'" #-}