From 603e1c20c3eea9091f618ce72e6dc3b633535826 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Sat, 2 Feb 2013 21:55:57 +0100 Subject: Bail when different compilers for the same id --- src/Hakyll/Core/Rules/Internal.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/Hakyll') diff --git a/src/Hakyll/Core/Rules/Internal.hs b/src/Hakyll/Core/Rules/Internal.hs index 10ca919..09d9b1e 100644 --- a/src/Hakyll/Core/Rules/Internal.hs +++ b/src/Hakyll/Core/Rules/Internal.hs @@ -16,9 +16,9 @@ import Control.Applicative (Applicative, (<$>)) import Control.Monad.Reader (ask) import Control.Monad.RWS (RWST, runRWST) import Control.Monad.Trans (liftIO) -import qualified Data.Map as M import Data.Monoid (Monoid, mappend, mempty) import Data.Set (Set) +import qualified Data.Set as S -------------------------------------------------------------------------------- @@ -92,7 +92,12 @@ instance MonadMetadata Rules where runRules :: Rules a -> Provider -> IO RuleSet runRules rules provider = do (_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState - return $ nubCompilers ruleSet + case findDuplicate (map fst $ rulesCompilers ruleSet) of + Nothing -> return ruleSet + Just id' -> error $ + "Hakyll.Core.Rules.Internal: two different rules for " ++ + show id' ++ " exist, bailing out" + where env = RulesRead { rulesProvider = provider @@ -102,9 +107,10 @@ runRules rules provider = do -------------------------------------------------------------------------------- --- | Remove duplicate compilers from the 'RuleSet'. When two compilers match an --- item, we prefer the first one -nubCompilers :: RuleSet -> RuleSet -nubCompilers set = set {rulesCompilers = nubCompilers' (rulesCompilers set)} +findDuplicate :: Ord a => [a] -> Maybe a +findDuplicate = go S.empty where - nubCompilers' = M.toList . M.fromListWith (flip const) + go _ [] = Nothing + go s (x : xs) + | x `S.member` s = Just x + | otherwise = go (S.insert x s) xs -- cgit v1.2.3