on master help sign in
Bail when different compilers for the same id
603e1c2Jasper Van der Jeugt
src/Hakyll/Core/Rules/Internal.hs+13−7
@@ -16,9 +16,9 @@ import Control.Applicative (Applicative, (<$>))
16import Control.Monad.Reader (ask)
16import Control.Monad.Reader (ask)
17import Control.Monad.RWS (RWST, runRWST)
17import Control.Monad.RWS (RWST, runRWST)
18import Control.Monad.Trans (liftIO)
18import Control.Monad.Trans (liftIO)
19−import qualified Data.Map as M
20import Data.Monoid (Monoid, mappend, mempty)
19import Data.Monoid (Monoid, mappend, mempty)
21import Data.Set (Set)
20import Data.Set (Set)
21+import qualified Data.Set as S
22
22
23
23
24--------------------------------------------------------------------------------
24--------------------------------------------------------------------------------
@@ -92,7 +92,12 @@ instance MonadMetadata Rules where
92runRules :: Rules a -> Provider -> IO RuleSet
92runRules :: Rules a -> Provider -> IO RuleSet
93runRules rules provider = do
93runRules rules provider = do
94 (_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
94 (_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
95− return $ nubCompilers ruleSet
95+ case findDuplicate (map fst $ rulesCompilers ruleSet) of
96+ Nothing -> return ruleSet
97+ Just id' -> error $
98+ "Hakyll.Core.Rules.Internal: two different rules for " ++
99+ show id' ++ " exist, bailing out"
100+
96 where
101 where
97 env = RulesRead
102 env = RulesRead
98 { rulesProvider = provider
103 { rulesProvider = provider
@@ -102,9 +107,10 @@ runRules rules provider = do
102
107
103
108
104--------------------------------------------------------------------------------
109--------------------------------------------------------------------------------
105−-- | Remove duplicate compilers from the 'RuleSet'. When two compilers match an
110+findDuplicate :: Ord a => [a] -> Maybe a
106−-- item, we prefer the first one
111+findDuplicate = go S.empty
107−nubCompilers :: RuleSet -> RuleSet
108−nubCompilers set = set {rulesCompilers = nubCompilers' (rulesCompilers set)}
109 where
112 where
110− nubCompilers' = M.toList . M.fromListWith (flip const)
113+ go _ [] = Nothing
114+ go s (x : xs)
115+ | x `S.member` s = Just x
116+ | otherwise = go (S.insert x s) xs