Pretty print settings parsing errors
All checks were successful
Build / audit (push) Successful in 8s
Build / test (push) Successful in 1h3m30s

This commit is contained in:
Eugen Wissner 2024-09-08 16:44:57 +02:00
parent 4f74c2ec10
commit 1418e0ae46
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -6,7 +6,7 @@ module Main
( main
) where
import Control.Exception (Exception(..), handle)
import Control.Exception (Exception(..), handle, SomeException(..))
import Data.Char (isNumber)
import Control.Monad.Catch (MonadThrow(..))
import Control.Monad.IO.Class (MonadIO(..))
@ -20,6 +20,7 @@ import SlackBuilder.Update
import qualified Toml
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Control.Monad.Trans.Reader (ReaderT(..))
import SlackBuilder.Package (PackageDescription(..))
import qualified SlackBuilder.Package as Package
@ -258,15 +259,22 @@ check = for_ autoUpdatable go
>> liftIO (putStrLn "")
main :: IO ()
main = do
programCommand <- execParser slackBuilderParser
settings <- Toml.decodeFile settingsCodec "config/config.toml"
handle handleException
$ flip runReaderT settings
main = execParser slackBuilderParser
>>= handle handleException . withCommandLine
where
withCommandLine programCommand = do
settingsResult <- Toml.decodeFileEither settingsCodec configurationFile
case settingsResult of
Right settings -> flip runReaderT settings
$ runSlackBuilderT
$ executeCommand programCommand
where
handleException :: SlackBuilderException -> IO ()
Left settingsErrors
-> setSGR [SetColor Foreground Dull Red]
>> putStrLn (configurationFile <> " parsing failed.")
>> setSGR [Reset]
>> Text.putStr (Toml.prettyTomlDecodeErrors settingsErrors)
configurationFile = "config/config.toml"
handleException :: SomeException -> IO ()
handleException slackBuilderException
= setSGR [SetColor Foreground Dull Red]
>> putStrLn (displayException slackBuilderException)