on master help sign in
Better error for `cached` on non-existing file
2577bd4Jasper Van der Jeugt
src/Hakyll/Core/Compiler.hs+10−1
@@ -28,7 +28,7 @@ module Hakyll.Core.Compiler
28
28
29
29
30--------------------------------------------------------------------------------
30--------------------------------------------------------------------------------
31−import Control.Monad (when)
31+import Control.Monad (when, unless)
32import Data.Binary (Binary)
32import Data.Binary (Binary)
33import Data.ByteString.Lazy (ByteString)
33import Data.ByteString.Lazy (ByteString)
34import Data.Typeable (Typeable)
34import Data.Typeable (Typeable)
@@ -149,6 +149,10 @@ cached name compiler = do
149 id' <- compilerUnderlying <$> compilerAsk
149 id' <- compilerUnderlying <$> compilerAsk
150 store <- compilerStore <$> compilerAsk
150 store <- compilerStore <$> compilerAsk
151 provider <- compilerProvider <$> compilerAsk
151 provider <- compilerProvider <$> compilerAsk
152+
153+ -- Give a better error message when the resource is not there at all.
154+ unless (resourceExists provider id') $ fail $ itDoesntEvenExist id'
155+
152 let modified = resourceModified provider id'
156 let modified = resourceModified provider id'
153 if modified
157 if modified
154 then do
158 then do
@@ -166,6 +170,11 @@ cached name compiler = do
166 "Hakyll.Core.Compiler.cached: Cache corrupt! " ++
170 "Hakyll.Core.Compiler.cached: Cache corrupt! " ++
167 "Try running: " ++ progName ++ " clean"
171 "Try running: " ++ progName ++ " clean"
168
172
173+ itDoesntEvenExist id' =
174+ "Hakyll.Core.Compiler.cached: You are trying to (perhaps " ++
175+ "indirectly) use `cached` on a non-existing resource: there " ++
176+ "is no file backing " ++ show id'
177+
169
178
170--------------------------------------------------------------------------------
179--------------------------------------------------------------------------------
171unsafeCompiler :: IO a -> Compiler a
180unsafeCompiler :: IO a -> Compiler a