diff --git a/src/Main.hs b/src/Main.hs index c714459..4929e7e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -6,9 +6,8 @@ module Main ( main ) where -import Control.Exception (Exception(..), handle, SomeException(..)) import Data.Char (isNumber) -import Control.Monad.Catch (MonadThrow(..)) +import Control.Monad.Catch (MonadThrow(..), handle) import Control.Monad.IO.Class (MonadIO(..)) import qualified Data.Map as Map import Options.Applicative (execParser) @@ -257,7 +256,7 @@ autoUpdatable = up2Date :: Maybe Text -> SlackBuilderT () up2Date = \case - Nothing -> for_ autoUpdatable go + Nothing -> for_ autoUpdatable $ handle handleException . go Just packageName | Just foundPackage <- find ((packageName ==) . getField @"name") autoUpdatable -> go foundPackage @@ -268,7 +267,7 @@ up2Date = \case >> liftIO (putStrLn "") check :: SlackBuilderT () -check = for_ autoUpdatable go +check = for_ autoUpdatable $ handle handleException . go where go package = getAndLogLatest package >>= mapM_ checkUpdateAvailability @@ -290,11 +289,6 @@ main = execParser slackBuilderParser >> setSGR [Reset] >> Text.putStr (Toml.prettyTomlDecodeErrors settingsErrors) configurationFile = "config/config.toml" - handleException :: SomeException -> IO () - handleException slackBuilderException - = setSGR [SetColor Foreground Dull Red] - >> putStrLn (displayException slackBuilderException) - >> setSGR [Reset] executeCommand = \case CheckCommand -> check Up2DateCommand packageName -> up2Date packageName diff --git a/src/SlackBuilder/Update.hs b/src/SlackBuilder/Update.hs index 0c7ce6f..003afb7 100644 --- a/src/SlackBuilder/Update.hs +++ b/src/SlackBuilder/Update.hs @@ -7,10 +7,13 @@ module SlackBuilder.Update , cloneFromGit , downloadWithTemplate , getAndLogLatest + , handleException , reuploadWithTemplate , updatePackageIfRequired ) where +import Control.Exception (Exception(..), SomeException(..)) +import Control.Monad.Catch (MonadCatch(..)) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad.Trans.Reader (asks) import qualified Data.ByteString as ByteString @@ -254,3 +257,9 @@ findCategory packageName = do . (currentDirectory ) in filterM directoryFilter accumulatedDirectories >>= traverse (go currentDirectory found) <&> concat + +handleException :: (MonadIO m, MonadCatch m) => SomeException -> m () +handleException slackBuilderException + = liftIO (setSGR [SetColor Foreground Dull Red]) + >> liftIO (putStrLn (displayException slackBuilderException)) + >> liftIO (setSGR [Reset])