diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2024-04-18 20:45:56 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2024-04-18 20:45:56 +0200 |
commit | c93e766b2dbe0e3ae3761ec33cee027f27145108 (patch) | |
tree | b94097602b0656a898132715d4486adc74606ee5 /main | |
parent | fc69cbaf3306bd3840db2cb48cb34996127a20db (diff) |
Catch IO exceptions thrown during command execution
Diffstat (limited to 'main')
-rw-r--r-- | main/Main.hs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/main/Main.hs b/main/Main.hs index 5dbad60..d94c9dd 100644 --- a/main/Main.hs +++ b/main/Main.hs @@ -5,6 +5,7 @@ module Main (main) where import Control.Arrow (first) import Control.Concurrent +import Control.Exception import Control.Monad import Control.Monad.Except import Control.Monad.Reader @@ -265,11 +266,16 @@ data CommandContext = NoContext | SelectedContact Contact newtype CommandM a = CommandM (ReaderT CommandInput (StateT CommandState (ExceptT String IO)) a) - deriving (Functor, Applicative, Monad, MonadIO, MonadReader CommandInput, MonadState CommandState, MonadError String) + deriving (Functor, Applicative, Monad, MonadReader CommandInput, MonadState CommandState, MonadError String) instance MonadFail CommandM where fail = throwError +instance MonadIO CommandM where + liftIO act = CommandM (liftIO (try act)) >>= \case + Left (e :: SomeException) -> throwError (show e) + Right x -> return x + instance MonadRandom CommandM where getRandomBytes = liftIO . getRandomBytes |