on master help sign in
More better errors
dfe14d2Jasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+11−7
@@ -213,12 +213,16 @@ getDependency id' = CompilerM $ do
213 store <- compilerStore <$> ask
213 store <- compilerStore <$> ask
214 result <- liftIO $ storeGet store "Hakyll.Core.Compiler.runCompiler" id'
214 result <- liftIO $ storeGet store "Hakyll.Core.Compiler.runCompiler" id'
215 case result of
215 case result of
216− Nothing -> throwError error'
216+ NotFound -> throwError notFound
217+ WrongType -> throwError wrongType
217− Just x -> return x
218+ Found x -> return x
218 where
219 where
219− error' = "Hakyll.Core.Compiler.getDependency: " ++ show id'
220+ notFound = "Hakyll.Core.Compiler.getDependency: " ++ show id'
220− ++ " not found in the cache, the cache might be corrupted or"
221+ ++ " not found in the cache, the cache might be corrupted or"
221− ++ " the item you are referring to might not exist"
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"
222
226
223-- | Variant of 'require' which drops the current value
227-- | Variant of 'require' which drops the current value
224--
228--
@@ -289,8 +293,8 @@ cached name (Compiler d j) = Compiler d $ const $ CompilerM $ do
289 liftIO $ storeSet store name identifier v
293 liftIO $ storeSet store name identifier v
290 return v
294 return v
291 else do v <- liftIO $ storeGet store name identifier
295 else do v <- liftIO $ storeGet store name identifier
292− case v of Just v' -> return v'
296+ case v of Found v' -> return v'
293− Nothing -> throwError error'
297+ _ -> throwError error'
294 where
298 where
295 error' = "Hakyll.Core.Compiler.cached: Cache corrupt!"
299 error' = "Hakyll.Core.Compiler.cached: Cache corrupt!"
296
300
src/Hakyll/Core/Resource/Provider.hs+1−1
@@ -90,7 +90,7 @@ digestModified provider store resource = do
90 -- Calculate the digest for the resource
90 -- Calculate the digest for the resource
91 newDigest <- resourceDigest provider resource
91 newDigest <- resourceDigest provider resource
92 -- Check digests
92 -- Check digests
93− if Just newDigest == lastDigest
93+ if Found newDigest == lastDigest
94 -- All is fine, not modified
94 -- All is fine, not modified
95 then return False
95 then return False
96 -- Resource modified; store new digest
96 -- 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)
14import Data.Map (Map)
14import Data.Map (Map)
15import qualified Data.Map as M
15import qualified Data.Map as M
16import Data.Monoid (mempty, mappend)
16import Data.Monoid (mempty, mappend)
17−import Data.Maybe (fromMaybe)
18import System.FilePath ((</>))
17import System.FilePath ((</>))
19import qualified Data.Set as S
18import qualified Data.Set as S
20
19
@@ -48,8 +47,9 @@ run configuration rules = do
48
47
49 -- Fetch the old graph from the store. If we don't find it, we consider this
48 -- Fetch the old graph from the store. If we don't find it, we consider this
50 -- to be the first run
49 -- 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)
53
53
54 let ruleSet = runRules rules provider
54 let ruleSet = runRules rules provider
55 compilers = rulesCompilers ruleSet
55 compilers = rulesCompilers ruleSet
src/Hakyll/Core/Store.hs+14−4
@@ -3,6 +3,7 @@
3{-# LANGUAGE ExistentialQuantification #-}
3{-# LANGUAGE ExistentialQuantification #-}
4module Hakyll.Core.Store
4module Hakyll.Core.Store
5 ( Store
5 ( Store
6+ , StoreGet (..)
6 , makeStore
7 , makeStore
7 , storeSet
8 , storeSet
8 , storeGet
9 , storeGet
@@ -25,6 +26,13 @@ import Hakyll.Core.Util.File
25--
26--
26data Storable = forall a. (Binary a, Typeable a) => Storable a
27data Storable = forall a. (Binary a, Typeable a) => Storable a
27
28
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+
28-- | Data structure used for the store
36-- | Data structure used for the store
29--
37--
30data Store = Store
38data Store = Store
@@ -72,22 +80,24 @@ storeSet store name identifier value = do
72-- | Load an item
80-- | Load an item
73--
81--
74storeGet :: (Binary a, Typeable a)
82storeGet :: (Binary a, Typeable a)
75− => Store -> String -> Identifier -> IO (Maybe a)
83+ => Store -> String -> Identifier -> IO (StoreGet a)
76storeGet store name identifier = do
84storeGet store name identifier = do
77 -- First check the in-memory map
85 -- First check the in-memory map
78 map' <- readMVar $ storeMap store
86 map' <- readMVar $ storeMap store
79 case M.lookup path map' of
87 case M.lookup path map' of
80 -- Found in the in-memory map
88 -- 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'
82 -- Not found in the map, try the filesystem
92 -- Not found in the map, try the filesystem
83 Nothing -> do
93 Nothing -> do
84 exists <- doesFileExist path
94 exists <- doesFileExist path
85 if not exists
95 if not exists
86 -- Not found in the filesystem either
96 -- Not found in the filesystem either
87− then return Nothing
97+ then return NotFound
88 -- Found in the filesystem
98 -- Found in the filesystem
89 else do v <- decodeFile path
99 else do v <- decodeFile path
90 addToMap store path v
100 addToMap store path v
91− return $ Just v
101+ return $ Found v
92 where
102 where
93 path = makePath store name identifier
103 path = makePath store name identifier