2023-12-23 22:15:10 +01:00
|
|
|
{- This Source Code Form is subject to the terms of the Mozilla Public License,
|
|
|
|
v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
obtain one at https://mozilla.org/MPL/2.0/. -}
|
|
|
|
|
2023-12-12 18:51:44 +01:00
|
|
|
-- | Transformers and exceptions.
|
2023-08-15 10:33:19 +02:00
|
|
|
module SlackBuilder.Trans
|
2023-12-11 08:14:55 +01:00
|
|
|
( SlackBuilderException(..)
|
|
|
|
, SlackBuilderT(..)
|
2024-01-04 09:36:11 +01:00
|
|
|
, relativeToRepository
|
2023-08-15 10:33:19 +02:00
|
|
|
) where
|
|
|
|
|
2024-01-04 09:36:11 +01:00
|
|
|
import Control.Monad.Trans.Reader (ReaderT(..), asks)
|
2023-12-11 08:14:55 +01:00
|
|
|
import Data.Text (Text)
|
2023-08-15 10:33:19 +02:00
|
|
|
import SlackBuilder.Config
|
|
|
|
import Control.Monad.IO.Class (MonadIO(..))
|
2023-10-01 17:19:06 +02:00
|
|
|
import Control.Monad.Catch (MonadCatch(..), MonadThrow(..))
|
2023-12-11 08:14:55 +01:00
|
|
|
import Control.Exception (Exception(..))
|
2024-01-04 09:36:11 +01:00
|
|
|
import System.FilePath ((</>))
|
2024-03-03 17:12:29 +01:00
|
|
|
import Text.URI (URI)
|
2023-12-11 08:14:55 +01:00
|
|
|
|
2024-03-03 17:12:29 +01:00
|
|
|
data SlackBuilderException
|
|
|
|
= UpdaterNotFound Text
|
|
|
|
| HttpsUrlExpected URI
|
2023-12-11 08:14:55 +01:00
|
|
|
deriving Show
|
|
|
|
|
|
|
|
instance Exception SlackBuilderException
|
2023-08-15 10:33:19 +02:00
|
|
|
|
|
|
|
newtype SlackBuilderT a = SlackBuilderT
|
|
|
|
{ runSlackBuilderT :: ReaderT Settings IO a
|
|
|
|
}
|
|
|
|
|
2024-01-04 09:36:11 +01:00
|
|
|
relativeToRepository :: FilePath -> SlackBuilderT FilePath
|
|
|
|
relativeToRepository filePath =
|
|
|
|
(</> filePath) <$> SlackBuilderT (asks repository)
|
|
|
|
|
2023-08-15 10:33:19 +02:00
|
|
|
instance Functor SlackBuilderT
|
|
|
|
where
|
|
|
|
fmap f (SlackBuilderT slackBuilderT) = SlackBuilderT $ f <$> slackBuilderT
|
|
|
|
|
|
|
|
instance Applicative SlackBuilderT
|
|
|
|
where
|
|
|
|
pure = SlackBuilderT . pure
|
|
|
|
(SlackBuilderT f) <*> (SlackBuilderT x) = SlackBuilderT $ f <*> x
|
|
|
|
|
|
|
|
instance Monad SlackBuilderT
|
|
|
|
where
|
|
|
|
return = pure
|
|
|
|
(SlackBuilderT x) >>= f = SlackBuilderT $ x >>= runSlackBuilderT . f
|
|
|
|
|
|
|
|
instance MonadIO SlackBuilderT
|
|
|
|
where
|
|
|
|
liftIO = SlackBuilderT . liftIO
|
2023-10-01 17:19:06 +02:00
|
|
|
|
|
|
|
instance MonadThrow SlackBuilderT
|
|
|
|
where
|
|
|
|
throwM = SlackBuilderT . throwM
|
|
|
|
|
|
|
|
instance MonadCatch SlackBuilderT
|
|
|
|
where
|
|
|
|
catch (SlackBuilderT action) handler =
|
|
|
|
SlackBuilderT $ catch action $ runSlackBuilderT . handler
|