on master help sign in
Bail when different compilers for the same id
commit603e1c20c3eea9091f618ce72e6dc3b633535826 authorJasper Van der Jeugt <m@jaspervdj.be> dateSat 2 Feb 2013, 21:55 (14 years ago) parent1b6dd8a
1 file changed+13−7
src/Hakyll/Core/Rules/Internal.hs+13−7
src/Hakyll/Core/Rules/Internal.hs+13−7
@@ -16,9 +16,9 @@ import Control.Applicative (Applicative, (<$>))
1616import Control.Monad.Reader (ask)
1717import Control.Monad.RWS (RWST, runRWST)
1818import Control.Monad.Trans (liftIO)
19−import qualified Data.Map as M
2019import Data.Monoid (Monoid, mappend, mempty)
2120import Data.Set (Set)
21+import qualified Data.Set as S
2222
2323
2424--------------------------------------------------------------------------------
@@ -92,7 +92,12 @@ instance MonadMetadata Rules where
9292runRules :: Rules a -> Provider -> IO RuleSet
9393runRules rules provider = do
9494 (_, _, 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+
96101 where
97102 env = RulesRead
98103 { rulesProvider = provider
@@ -102,9 +107,10 @@ runRules rules provider = do
102107
103108
104109--------------------------------------------------------------------------------
105−-- | Remove duplicate compilers from the 'RuleSet'. When two compilers match an
106−-- item, we prefer the first one
107−nubCompilers :: RuleSet -> RuleSet
108−nubCompilers set = set {rulesCompilers = nubCompilers' (rulesCompilers set)}
110+findDuplicate :: Ord a => [a] -> Maybe a
111+findDuplicate = go S.empty
109112 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