on master help sign in
More better errors
commitdfe14d295ec7c3f75a0ea845d34de00cda2986e9 authorJasper Van der Jeugt <jaspervdj@gmail.com> dateTue 17 May 2011, 10:57 (15 years ago) parent6e207e4
4 files changed+29−15
src/Hakyll/Core/Compiler.hs+11−7 src/Hakyll/Core/Resource/Provider.hs+1−1 src/Hakyll/Core/Run.hs+3−3 src/Hakyll/Core/Store.hs+14−4
src/Hakyll/Core/Compiler.hs+11−7
@@ -213,12 +213,16 @@ getDependency id' = CompilerM $ do
213213 store <- compilerStore <$> ask
214214 result <- liftIO $ storeGet store "Hakyll.Core.Compiler.runCompiler" id'
215215 case result of
216− Nothing -> throwError error'
217− Just x -> return x
216+ NotFound -> throwError notFound
217+ WrongType -> throwError wrongType
218+ Found x -> return x
218219 where
219− error' = "Hakyll.Core.Compiler.getDependency: " ++ show id'
220− ++ " not found in the cache, the cache might be corrupted or"
221− ++ " the item you are referring to might not exist"
220+ notFound = "Hakyll.Core.Compiler.getDependency: " ++ show id'
221+ ++ " not found in the cache, the cache might be corrupted or"
222+ ++ " the item you are referring to might not exist"
223+ wrongType = "Hakyll.Core.Compiler.getDependency: " ++ show id'
224+ ++ " was found in the cache, but does not have the expected "
225+ ++ " type"
222226
223227-- | Variant of 'require' which drops the current value
224228--
@@ -289,8 +293,8 @@ cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
289293 liftIO $ storeSet store name identifier v
290294 return v
291295 else do v <- liftIO $ storeGet store name identifier
292− case v of Just v' -> return v'
293− Nothing -> throwError error'
296+ case v of Found v' -> return v'
297+ _ -> throwError error'
294298 where
295299 error' = "Hakyll.Core.Compiler.cached: Cache corrupt!"
296300
src/Hakyll/Core/Resource/Provider.hs+1−1
@@ -90,7 +90,7 @@ digestModified provider store resource = do
9090 -- Calculate the digest for the resource
9191 newDigest <- resourceDigest provider resource
9292 -- Check digests
93− if Just newDigest == lastDigest
93+ if Found newDigest == lastDigest
9494 -- All is fine, not modified
9595 then return False
9696 -- Resource modified; store new digest
src/Hakyll/Core/Run.hs+3−3
@@ -14,7 +14,6 @@ import Control.Monad.State.Strict (StateT, runStateT, get, put)
1414import Data.Map (Map)
1515import qualified Data.Map as M
1616import Data.Monoid (mempty, mappend)
17−import Data.Maybe (fromMaybe)
1817import System.FilePath ((</>))
1918import qualified Data.Set as S
2019
@@ -48,8 +47,9 @@ run configuration rules = do
4847
4948 -- Fetch the old graph from the store. If we don't find it, we consider this
5049 -- to be the first run
51− (firstRun, oldGraph) <- fromMaybe (True, mempty) . fmap ((,) False) <$>
52− storeGet store "Hakyll.Core.Run.run" "dependencies"
50+ graph <- storeGet store "Hakyll.Core.Run.run" "dependencies"
51+ let (firstRun, oldGraph) = case graph of Found g -> (False, g)
52+ _ -> (True, mempty)
5353
5454 let ruleSet = runRules rules provider
5555 compilers = rulesCompilers ruleSet
src/Hakyll/Core/Store.hs+14−4
@@ -3,6 +3,7 @@
33{-# LANGUAGE ExistentialQuantification #-}
44module Hakyll.Core.Store
55 ( Store
6+ , StoreGet (..)
67 , makeStore
78 , storeSet
89 , storeGet
@@ -25,6 +26,13 @@ import Hakyll.Core.Util.File
2526--
2627data Storable = forall a. (Binary a, Typeable a) => Storable a
2728
29+-- | Result when an item from the store
30+--
31+data StoreGet a = Found a
32+ | NotFound
33+ | WrongType
34+ deriving (Show, Eq, Ord)
35+
2836-- | Data structure used for the store
2937--
3038data Store = Store
@@ -72,22 +80,24 @@ storeSet store name identifier value = do
7280-- | Load an item
7381--
7482storeGet :: (Binary a, Typeable a)
75− => Store -> String -> Identifier -> IO (Maybe a)
83+ => Store -> String -> Identifier -> IO (StoreGet a)
7684storeGet store name identifier = do
7785 -- First check the in-memory map
7886 map' <- readMVar $ storeMap store
7987 case M.lookup path map' of
8088 -- Found in the in-memory map
81− Just (Storable s) -> return $ cast s
89+ Just (Storable s) -> return $ case cast s of
90+ Nothing -> WrongType
91+ Just s' -> Found s'
8292 -- Not found in the map, try the filesystem
8393 Nothing -> do
8494 exists <- doesFileExist path
8595 if not exists
8696 -- Not found in the filesystem either
87− then return Nothing
97+ then return NotFound
8898 -- Found in the filesystem
8999 else do v <- decodeFile path
90100 addToMap store path v
91− return $ Just v
101+ return $ Found v
92102 where
93103 path = makePath store name identifier