summaryrefslogtreecommitdiff
path: root/src/Hakyll
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-02-02 21:55:57 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2013-02-02 21:56:42 +0100
commit603e1c20c3eea9091f618ce72e6dc3b633535826 (patch)
treecd08743d6a3694c50ded7db12b5f7dbb43fa36ce /src/Hakyll
parent1b6dd8a37369a63669f3b6cc76c856f94fb65fd1 (diff)
downloadhakyll-603e1c20c3eea9091f618ce72e6dc3b633535826.tar.gz
Bail when different compilers for the same id
Diffstat (limited to 'src/Hakyll')
-rw-r--r--src/Hakyll/Core/Rules/Internal.hs20
1 files changed, 13 insertions, 7 deletions
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