-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert runCompatibleTransactionCmd to use RIO monad
- Loading branch information
Showing
11 changed files
with
180 additions
and
108 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
module Cardano.CLI.Compatible.Exception | ||
( CustomCliException (..) | ||
, throwCliError | ||
, fromEitherCli | ||
, fromEitherIOCli | ||
) | ||
where | ||
|
||
import Cardano.Api | ||
|
||
import GHC.Stack | ||
|
||
import RIO | ||
|
||
data CustomCliException where | ||
CustomCliException | ||
:: (Show error, Typeable error, Error error) | ||
=> error -> CallStack -> CustomCliException | ||
|
||
deriving instance Show CustomCliException | ||
|
||
instance Exception CustomCliException where | ||
displayException (CustomCliException e cStack) = | ||
unlines | ||
[ show (prettyError e) | ||
, prettyCallStack cStack | ||
] | ||
|
||
throwCliError :: MonadIO m => CustomCliException -> m a | ||
throwCliError = throwIO | ||
|
||
fromEitherCli :: (HasCallStack, MonadIO m, Show e, Typeable e, Error e) => Either e a -> m a | ||
fromEitherCli = \case | ||
Left e -> throwCliError $ CustomCliException e callStack | ||
Right a -> return a | ||
|
||
fromEitherIOCli :: (HasCallStack, MonadIO m, Show e, Typeable e, Error e) => IO (Either e a) -> m a | ||
fromEitherIOCli action = do | ||
result <- liftIO action | ||
case result of | ||
Left e -> throwCliError $ CustomCliException e callStack | ||
Right a -> return a |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
|
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
Oops, something went wrong.