Generalize handleException
All checks were successful
Build / audit (push) Successful in 6s
Build / test (push) Successful in 14m55s

This commit is contained in:
Eugen Wissner 2024-09-14 11:32:34 +02:00
parent 3dde41e0d4
commit 5b4caa8ff7
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
2 changed files with 12 additions and 9 deletions

View File

@ -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

View File

@ -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])