Skip to content

Commit

Permalink
tolerate unexpected cache miss (jaspervdj#876)
Browse files Browse the repository at this point in the history
If a Hakyll program termiantes abnormally (e.g. due to kill signal),
a subsequent run can fail because expected cache entries are not
present.  The missing cache entry is regarded as corruption; Hakyll
advises the user to delete the cache and start over.

But this scenario is recoverable, and the user need not be bothered.
If `Store.get` returns `NotFound`, don't fail - compile the item!
Other results (e.g. `WrongType`) still throw an error.
  • Loading branch information
frasertweedale authored Sep 10, 2021
1 parent dc91ea5 commit 7ed78ca
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/Hakyll/Core/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ cached name compiler = do
unless (resourceExists provider id') $ fail $ itDoesntEvenExist id'

let modified = resourceModified provider id'
k = [name, show id']
go = compiler >>= \v -> v <$ compilerUnsafeIO (Store.set store k v)
if modified
then do
x <- compiler
compilerUnsafeIO $ Store.set store [name, show id'] x
return x
else do
compilerTellCacheHits 1
x <- compilerUnsafeIO $ Store.get store [name, show id']
progName <- compilerUnsafeIO getProgName
case x of Store.Found x' -> return x'
_ -> fail $ error' progName
then go
else compilerUnsafeIO (Store.get store k) >>= \r -> case r of
-- found: report cache hit and return value
Store.Found v -> v <$ compilerTellCacheHits 1
-- not found: unexpected, but recoverable
Store.NotFound -> go
-- other results: unrecoverable error
_ -> fail . error' =<< compilerUnsafeIO getProgName
where
error' progName =
"Hakyll.Core.Compiler.cached: Cache corrupt! " ++
Expand Down

0 comments on commit 7ed78ca

Please sign in to comment.