@@ -28,6 +28,7 @@ module Hakyll.Core.Compiler.Internal
28import Control.Applicative (Alternative (..),
28import Control.Applicative (Alternative (..),
29 Applicative (..), (<$>))
29 Applicative (..), (<$>))
30import Control.Exception (SomeException, handle)
30import Control.Exception (SomeException, handle)
31+import Control.Monad (forM_)
31import Data.Monoid (Monoid (..))
32import Data.Monoid (Monoid (..))
32import Data.Set (Set)
33import Data.Set (Set)
33import qualified Data.Set as S
34import qualified Data.Set as S
@@ -38,7 +39,8 @@ import Hakyll.Core.Configuration
38import Hakyll.Core.Dependencies
39import Hakyll.Core.Dependencies
39import Hakyll.Core.Identifier
40import Hakyll.Core.Identifier
40import Hakyll.Core.Identifier.Pattern
41import Hakyll.Core.Identifier.Pattern
41−import Hakyll.Core.Logger
42+import Hakyll.Core.Logger (Logger)
43+import qualified Hakyll.Core.Logger as Logger
42import Hakyll.Core.Metadata
44import Hakyll.Core.Metadata
43import Hakyll.Core.Provider
45import Hakyll.Core.Provider
44import Hakyll.Core.Routes
46import Hakyll.Core.Routes
@@ -82,7 +84,7 @@ instance Monoid CompilerWrite where
82--------------------------------------------------------------------------------
84--------------------------------------------------------------------------------
83data CompilerResult a where
85data CompilerResult a where
84 CompilerDone :: a -> CompilerWrite -> CompilerResult a
86 CompilerDone :: a -> CompilerWrite -> CompilerResult a
85− CompilerError :: String -> CompilerResult a
87+ CompilerError :: [String] -> CompilerResult a
86 CompilerRequire :: Identifier -> Compiler a -> CompilerResult a
88 CompilerRequire :: Identifier -> Compiler a -> CompilerResult a
@@ -126,7 +128,7 @@ instance Monad Compiler where
126 CompilerRequire i c' -> return $ CompilerRequire i $ c' >>= f
128 CompilerRequire i c' -> return $ CompilerRequire i $ c' >>= f
127 {-# INLINE (>>=) #-}
129 {-# INLINE (>>=) #-}
129− fail = compilerThrow
131+ fail = compilerThrow . return
130 {-# INLINE fail #-}
132 {-# INLINE fail #-}
@@ -150,13 +152,17 @@ runCompiler :: Compiler a -> CompilerRead -> IO (CompilerResult a)
150runCompiler compiler read' = handle handler $ unCompiler compiler read'
152runCompiler compiler read' = handle handler $ unCompiler compiler read'
152 handler :: SomeException -> IO (CompilerResult a)
154 handler :: SomeException -> IO (CompilerResult a)
153− handler e = return $ CompilerError $ show e
155+ handler e = return $ CompilerError [show e]
156--------------------------------------------------------------------------------
158--------------------------------------------------------------------------------
157instance Alternative Compiler where
159instance Alternative Compiler where
160+ empty = compilerThrow []
161+ x <|> y = compilerCatch x $ \es -> do
162+ logger <- compilerLogger <$> compilerAsk
163+ forM_ es $ \e -> compilerUnsafeIO $ Logger.debug logger $
158− empty = compilerThrow "Hakyll.Core.Compiler.Internal: empty alternative"
164+ "Hakyll.Core.Compiler.Internal: Alternative failed: " ++ e
159− x <|> y = compilerCatch x (\_ -> y)
165+ y
160 {-# INLINE (<|>) #-}
166 {-# INLINE (<|>) #-}
@@ -173,13 +179,13 @@ compilerTell deps = Compiler $ \_ -> return $ CompilerDone () deps
175--------------------------------------------------------------------------------
181--------------------------------------------------------------------------------
176−compilerThrow :: String -> Compiler a
182+compilerThrow :: [String] -> Compiler a
177−compilerThrow e = Compiler $ \_ -> return $ CompilerError e
183+compilerThrow es = Compiler $ \_ -> return $ CompilerError es
178{-# INLINE compilerThrow #-}
184{-# INLINE compilerThrow #-}
181--------------------------------------------------------------------------------
187--------------------------------------------------------------------------------
182−compilerCatch :: Compiler a -> (String -> Compiler a) -> Compiler a
188+compilerCatch :: Compiler a -> ([String] -> Compiler a) -> Compiler a
183compilerCatch (Compiler x) f = Compiler $ \r -> do
189compilerCatch (Compiler x) f = Compiler $ \r -> do
184 res <- x r
190 res <- x r
185 case res of
191 case res of