From 2577bd4bb267ba66141524000a235c000178ea72 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 18 Mar 2017 14:46:23 +0100 Subject: Better error for `cached` on non-existing file --- src/Hakyll/Core/Compiler.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/Hakyll/Core/Compiler.hs') diff --git a/src/Hakyll/Core/Compiler.hs b/src/Hakyll/Core/Compiler.hs index ae9fbf1..42b24d6 100644 --- a/src/Hakyll/Core/Compiler.hs +++ b/src/Hakyll/Core/Compiler.hs @@ -28,7 +28,7 @@ module Hakyll.Core.Compiler -------------------------------------------------------------------------------- -import Control.Monad (when) +import Control.Monad (when, unless) import Data.Binary (Binary) import Data.ByteString.Lazy (ByteString) import Data.Typeable (Typeable) @@ -149,6 +149,10 @@ cached name compiler = do id' <- compilerUnderlying <$> compilerAsk store <- compilerStore <$> compilerAsk provider <- compilerProvider <$> compilerAsk + + -- Give a better error message when the resource is not there at all. + unless (resourceExists provider id') $ fail $ itDoesntEvenExist id' + let modified = resourceModified provider id' if modified then do @@ -166,6 +170,11 @@ cached name compiler = do "Hakyll.Core.Compiler.cached: Cache corrupt! " ++ "Try running: " ++ progName ++ " clean" + itDoesntEvenExist id' = + "Hakyll.Core.Compiler.cached: You are trying to (perhaps " ++ + "indirectly) use `cached` on a non-existing resource: there " ++ + "is no file backing " ++ show id' + -------------------------------------------------------------------------------- unsafeCompiler :: IO a -> Compiler a -- cgit v1.2.3