summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-11-22 13:56:17 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2013-11-22 13:56:17 +0100
commitffbce966075d258b16b44e6856333ef41e4487f4 (patch)
treecf233271079ded284c4edb0560874977172b3fc1
parent5e70351a40dca61f49f7a4dfb1c6384c71caf322 (diff)
downloadhakyll-ffbce966075d258b16b44e6856333ef41e4487f4.tar.gz
Throw an error in case of duplicate compilers
-rw-r--r--src/Hakyll/Core/Rules/Internal.hs22
-rw-r--r--src/Hakyll/Core/Runtime.hs3
2 files changed, 19 insertions, 6 deletions
diff --git a/src/Hakyll/Core/Rules/Internal.hs b/src/Hakyll/Core/Rules/Internal.hs
index a7c2059..72166c8 100644
--- a/src/Hakyll/Core/Rules/Internal.hs
+++ b/src/Hakyll/Core/Rules/Internal.hs
@@ -16,6 +16,7 @@ import Control.Applicative (Applicative, (<$>))
import Control.Monad.Reader (ask)
import Control.Monad.RWS (RWST, runRWST)
import Control.Monad.Trans (liftIO)
+import Data.Map (Map)
import qualified Data.Map as M
import Data.Monoid (Monoid, mappend, mempty)
import Data.Set (Set)
@@ -97,15 +98,26 @@ runRules rules provider = do
(_, _, ruleSet) <- runRWST (unRules rules) env emptyRulesState
-- Ensure compiler uniqueness
- let ruleSet' = ruleSet
- { rulesCompilers = M.toList $
- M.fromListWith (flip const) (rulesCompilers ruleSet)
- }
+ uniqueCompilers <- case fromListUnique (rulesCompilers ruleSet) of
+ Right m -> return m
+ Left id' -> error $
+ "Hakyll.Core.Rules.Internal.runRules: duplicate compiler for " ++
+ show id'
- return ruleSet'
+ return ruleSet {rulesCompilers = M.toList uniqueCompilers}
where
env = RulesRead
{ rulesProvider = provider
, rulesMatches = []
, rulesVersion = Nothing
}
+
+
+--------------------------------------------------------------------------------
+fromListUnique :: Ord k => [(k, v)] -> Either k (Map k v)
+fromListUnique = go M.empty
+ where
+ go m [] = Right m
+ go m ((k, v) : zs) = case M.lookup k m of
+ Nothing -> go (M.insert k v m) zs
+ Just _ -> Left k
diff --git a/src/Hakyll/Core/Runtime.hs b/src/Hakyll/Core/Runtime.hs
index 824d11b..208fcc3 100644
--- a/src/Hakyll/Core/Runtime.hs
+++ b/src/Hakyll/Core/Runtime.hs
@@ -53,7 +53,8 @@ run config verbosity rules = do
provider <- newProvider store (shouldIgnoreFile config) $
providerDirectory config
Logger.message logger "Running rules..."
- ruleSet <- runRules rules provider
+ Logger.flush logger
+ ruleSet <- runRules rules provider
-- Get old facts
mOldFacts <- Store.get store factsKey