summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Store.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-05-17 10:57:37 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-05-17 10:57:37 +0200
commitdfe14d295ec7c3f75a0ea845d34de00cda2986e9 (patch)
tree4eb9b711caecd518be647bdd49f0e8c0108c9e74 /src/Hakyll/Core/Store.hs
parent6e207e4793215c14d6dd429b88551173ca948abe (diff)
downloadhakyll-dfe14d295ec7c3f75a0ea845d34de00cda2986e9.tar.gz
More better errors
Diffstat (limited to 'src/Hakyll/Core/Store.hs')
-rw-r--r--src/Hakyll/Core/Store.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs
index e0d6774..7114afc 100644
--- a/src/Hakyll/Core/Store.hs
+++ b/src/Hakyll/Core/Store.hs
@@ -3,6 +3,7 @@
{-# LANGUAGE ExistentialQuantification #-}
module Hakyll.Core.Store
( Store
+ , StoreGet (..)
, makeStore
, storeSet
, storeGet
@@ -25,6 +26,13 @@ import Hakyll.Core.Util.File
--
data Storable = forall a. (Binary a, Typeable a) => Storable a
+-- | Result when an item from the store
+--
+data StoreGet a = Found a
+ | NotFound
+ | WrongType
+ deriving (Show, Eq, Ord)
+
-- | Data structure used for the store
--
data Store = Store
@@ -72,22 +80,24 @@ storeSet store name identifier value = do
-- | Load an item
--
storeGet :: (Binary a, Typeable a)
- => Store -> String -> Identifier -> IO (Maybe a)
+ => Store -> String -> Identifier -> IO (StoreGet a)
storeGet store name identifier = do
-- First check the in-memory map
map' <- readMVar $ storeMap store
case M.lookup path map' of
-- Found in the in-memory map
- Just (Storable s) -> return $ cast s
+ Just (Storable s) -> return $ case cast s of
+ Nothing -> WrongType
+ Just s' -> Found s'
-- Not found in the map, try the filesystem
Nothing -> do
exists <- doesFileExist path
if not exists
-- Not found in the filesystem either
- then return Nothing
+ then return NotFound
-- Found in the filesystem
else do v <- decodeFile path
addToMap store path v
- return $ Just v
+ return $ Found v
where
path = makePath store name identifier