module Cachix.API.Error
( escalate,
escalateAs,
)
where
import Control.Monad.Catch (MonadThrow (throwM))
import Protolude
escalateAs ::
(Exception exc, MonadThrow m) =>
(l -> exc) ->
Either l a ->
m a
escalateAs :: forall exc (m :: * -> *) l a.
(Exception exc, MonadThrow m) =>
(l -> exc) -> Either l a -> m a
escalateAs l -> exc
f = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a
throwM forall b c a. (b -> c) -> (a -> b) -> a -> c
. l -> exc
f) forall (f :: * -> *) a. Applicative f => a -> f a
pure
escalate ::
(Exception exc, MonadThrow m) =>
Either exc a ->
m a
escalate :: forall exc (m :: * -> *) a.
(Exception exc, MonadThrow m) =>
Either exc a -> m a
escalate = forall exc (m :: * -> *) l a.
(Exception exc, MonadThrow m) =>
(l -> exc) -> Either l a -> m a
escalateAs forall a. a -> a
identity