aboutsummaryrefslogtreecommitdiffstats
path: root/src/Store
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-05 18:00:05 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-05 18:00:05 +0200
commitc61333dd11f3ba8a4c8155cb58d7b081d2096a94 (patch)
treef32e845f4ca4d937afe37d170f0ff0ea1d0289a8 /src/Store
parentef93be6c2c8685176de5681bc7ebd349cd21d789 (diff)
add `Value` instance for `readFile`
Diffstat (limited to 'src/Store')
-rw-r--r--src/Store/Store.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Store/Store.hs b/src/Store/Store.hs
index e0bbdfb..1ec59ef 100644
--- a/src/Store/Store.hs
+++ b/src/Store/Store.hs
@@ -13,13 +13,14 @@ where
import Bindings.Libgit2 qualified as B
import Control.Arrow (first)
-import Control.Exception (Exception, finally)
+import Control.Exception (Exception, finally, throw)
import Control.Monad (when)
import Control.Monad.Catch (MonadCatch, MonadMask, MonadThrow, throwM)
import Control.Monad.Reader (MonadReader, ReaderT, ask, runReaderT)
import Control.Monad.State (MonadState, StateT, evalStateT, get, modify)
import Control.Monad.Trans (MonadIO, MonadTrans, lift, liftIO)
import Control.Monad.Trans.Resource (MonadResource, runResourceT)
+import Data.Aeson qualified as J
import Data.ByteString qualified as B
import Data.ByteString.Lazy qualified as LB
import Data.ByteString.UTF8 qualified as B
@@ -146,6 +147,11 @@ data InappropriateType = InappropriateType String FilePath
instance Exception InappropriateType
+data DecodeException = DecodeException String
+ deriving (Show)
+
+instance Exception DecodeException
+
class Readable a where
readFile :: FilePath -> StoreM a
@@ -158,6 +164,9 @@ instance Readable B.ByteString where
instance Readable LB.ByteString where
readFile = readFile' G.catBlobLazy
+instance Readable J.Value where
+ readFile = fmap (either (throw . DecodeException) id . J.eitherDecode) . readFile
+
readFile' ::
(G.BlobOid GB.LgRepo -> ReaderT GB.LgRepo IO a) ->
FilePath ->