From ffbce966075d258b16b44e6856333ef41e4487f4 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 22 Nov 2013 13:56:17 +0100 Subject: Throw an error in case of duplicate compilers --- src/Hakyll/Core/Rules/Internal.hs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/Hakyll/Core/Rules') 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 -- cgit v1.2.3