aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 ->