@@ -5,33 +5,35 @@ module Hakyll.Core.Run
8−import Prelude hiding (reverse)
9−import Control.Monad (filterM, forM_)
10−import Control.Monad.Trans (liftIO)
11import Control.Applicative (Applicative, (<$>))
8import Control.Applicative (Applicative, (<$>))
9+import Control.Exception (handle)
10+import Control.Monad (filterM, forM_)
11+import Control.Monad.Error (ErrorT, runErrorT, throwError)
12import Control.Monad.Reader (ReaderT, runReaderT, ask)
12import Control.Monad.Reader (ReaderT, runReaderT, ask)
13import Control.Monad.State.Strict (StateT, runStateT, get, put)
13import Control.Monad.State.Strict (StateT, runStateT, get, put)
14+import Control.Monad.Trans (liftIO)
14import Data.Map (Map)
15import Data.Map (Map)
15−import qualified Data.Map as M
16import Data.Monoid (mempty, mappend)
16import Data.Monoid (mempty, mappend)
17+import Prelude hiding (reverse)
17import System.FilePath ((</>))
18import System.FilePath ((</>))
19+import qualified Data.Map as M
18import qualified Data.Set as S
20import qualified Data.Set as S
20−import Hakyll.Core.Routes
21−import Hakyll.Core.Identifier
22−import Hakyll.Core.Util.File
23import Hakyll.Core.Compiler
22import Hakyll.Core.Compiler
24import Hakyll.Core.Compiler.Internal
23import Hakyll.Core.Compiler.Internal
24+import Hakyll.Core.Configuration
25+import Hakyll.Core.DependencyAnalyzer
26+import Hakyll.Core.DirectedGraph
27+import Hakyll.Core.Identifier
28+import Hakyll.Core.Logger
25import Hakyll.Core.Resource
29import Hakyll.Core.Resource
26import Hakyll.Core.Resource.Provider
30import Hakyll.Core.Resource.Provider
27import Hakyll.Core.Resource.Provider.File
31import Hakyll.Core.Resource.Provider.File
32+import Hakyll.Core.Routes
28import Hakyll.Core.Rules.Internal
33import Hakyll.Core.Rules.Internal
29−import Hakyll.Core.DirectedGraph
30−import Hakyll.Core.DependencyAnalyzer
31−import Hakyll.Core.Writable
32import Hakyll.Core.Store
34import Hakyll.Core.Store
33−import Hakyll.Core.Configuration
35+import Hakyll.Core.Util.File
34−import Hakyll.Core.Logger
36+import Hakyll.Core.Writable
36-- | Run all rules needed, return the rule set used
38-- | Run all rules needed, return the rule set used
@@ -66,14 +68,18 @@ run configuration rules = do
68 -- Run the program and fetch the resulting state
70 -- Run the program and fetch the resulting state
69− ((), state') <- runStateT stateT $ RuntimeState
71+ result <- runErrorT $ runStateT stateT $ RuntimeState
70 { hakyllAnalyzer = makeDependencyAnalyzer mempty (const False) oldGraph
72 { hakyllAnalyzer = makeDependencyAnalyzer mempty (const False) oldGraph
71 , hakyllCompilers = M.empty
73 , hakyllCompilers = M.empty
79+ Right ((), state') ->
74− -- We want to save the final dependency graph for the next run
80+ -- We want to save the final dependency graph for the next run
75− storeSet store "Hakyll.Core.Run.run" "dependencies" $
81+ storeSet store "Hakyll.Core.Run.run" "dependencies" $
76− analyzerGraph $ hakyllAnalyzer state'
82+ analyzerGraph $ hakyllAnalyzer state'
78 -- Flush and return
84 -- Flush and return
79 flushLogger logger
85 flushLogger logger
@@ -94,7 +100,8 @@ data RuntimeState = RuntimeState
96newtype Runtime a = Runtime
102newtype Runtime a = Runtime
97− { unRuntime :: ReaderT RuntimeEnvironment (StateT RuntimeState IO) a
103+ { unRuntime :: ReaderT RuntimeEnvironment
104+ (StateT RuntimeState (ErrorT String IO)) a
98 } deriving (Functor, Applicative, Monad)
105 } deriving (Functor, Applicative, Monad)
100-- | Add a number of compilers and continue using these compilers
107-- | Add a number of compilers and continue using these compilers
@@ -205,7 +212,5 @@ build id' = Runtime $ do
205 -- Actually I was just kidding, it's not hard at all
212 -- Actually I was just kidding, it's not hard at all
206 unRuntime $ addNewCompilers newCompilers
213 unRuntime $ addNewCompilers newCompilers
208− -- Some error happened, log and continue
215+ -- Some error happened, rethrow in Runtime monad
209− Left err -> do
216+ Left err -> throwError err
211− unRuntime stepAnalyzer