-
Notifications
You must be signed in to change notification settings - Fork 16
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
Integrate RIO monad part 1 #1033
base: master
Are you sure you want to change the base?
Conversation
69744e1
to
989ba8a
Compare
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.
Can we finish ADR first?
510a872
to
796aaf1
Compare
796aaf1
to
5a36d5d
Compare
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.
tactical merge block - I need to play with it
fromEitherIOCli action = do | ||
result <- liftIO action | ||
case result of | ||
Left e -> throwCliError $ CustomCliException e callStack | ||
Right a -> return a |
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.
fromEitherIOCli action = do | |
result <- liftIO action | |
case result of | |
Left e -> throwCliError $ CustomCliException e callStack | |
Right a -> return a | |
fromEitherIOCli action = liftIO action >>= fromEitherCli |
|
||
-- | This is a temporary function until all commands are migrated to RIO | ||
-- Once this happens we can remove this function and rely on `toplevelExceptionHandler` | ||
executeRio :: RIO () () -> IO () |
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.
What about an alias type CIO e a = HasCallStack => RIO e a
?
-> ExceptT CompatibleTransactionError IO () | ||
. HasCallStack | ||
=> CompatibleTransactionCmds era | ||
-> RIO () () |
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.
why concrete environment?
-> RIO () () | |
-> RIO e () |
executeRio :: RIO () () -> IO () | ||
executeRio r = do | ||
runRIO () r | ||
`catch` (\(e :: SomeException) -> putStrLn $ displayException e) |
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.
`catch` (\(e :: SomeException) -> putStrLn $ displayException e) | |
`catch` (\(e :: SomeException) -> hPutStr stderr $ displayException e) |
you'd need some imports for that
- The exitcode for cardano-cli here is
0
which is wrong.
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.
I think we can remove this handler and just let Cardano.CLI.TopHandler.toplevelExceptionHandler
do the job.
I'd just simplify Cardano.CLI.TopHandler.renderSomeException
to just use displayException
. I think show
there is just making output more noisy without any useful info.
throwCliError = throwIO | ||
|
||
fromEitherCli :: (HasCallStack, MonadIO m, Show e, Typeable e, Error e) => Either e a -> m a | ||
fromEitherCli = \case |
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.
fromEitherCli = \case | |
fromEitherCli = withFrozenCallStack $ \case |
] | ||
|
||
validatedRefInputs <- | ||
fromEitherCli . first CompatibleTxCmdError . validateTxInsReference $ |
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.
is this extra wrapping needed?
fromEitherCli . first CompatibleTxCmdError . validateTxInsReference $ | |
fromEitherCli . validateTxInsReference $ |
@@ -14,6 +14,9 @@ data BootstrapWitnessError | |||
MissingNetworkIdOrByronAddressError | |||
deriving Show | |||
|
|||
instance Error BootstrapWitnessError where | |||
prettyError = renderBootstrapWitnessError |
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.
Let's remove render*
functions for Error
s and just use prettyError
. Could be out of scope for this PR, because it's only slightly related.
data CustomCliException where | ||
CustomCliException | ||
:: (Show error, Typeable error, Error error) | ||
=> error -> CallStack -> CustomCliException |
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.
Why explicit CallStack
argument? The way it's used it can be an implicit one.
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE UndecidableInstances #-} |
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.
{-# LANGUAGE UndecidableInstances #-} |
|
||
fromEitherIOCli :: (HasCallStack, MonadIO m, Show e, Typeable e, Error e) => IO (Either e a) -> m a | ||
fromEitherIOCli action = do | ||
result <- liftIO action |
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.
This is more complicated than just liftIO
. We need to catch all synchronous exceptions here and wrap them, and also provide the call stack. So basically we need analogous wrapper to CustomCliException
but for Exception
s this time.
This is because IOException
for example does not carry the call stack with it (yet), so we should manually add it to it.
Unfortunately it'll be just a call stack up to fromEitherIOCli
call.
|
||
module Cardano.CLI.Compatible.Exception | ||
( CustomCliException (..) | ||
, throwCliError |
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.
I don't think this should be part of the API of this module. This function isn't useful on its own - you still need to attach call stack manually.
, throwCliError |
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.
Looks promising. We're getting there. Can you address my comments?
Changelog
Context
How to trust this PR
Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.
Checklist