diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-11-22 13:56:17 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-11-22 13:56:17 +0100 |
commit | ffbce966075d258b16b44e6856333ef41e4487f4 (patch) | |
tree | cf233271079ded284c4edb0560874977172b3fc1 /src/Hakyll/Core/Rules/Internal.hs | |
parent | 5e70351a40dca61f49f7a4dfb1c6384c71caf322 (diff) | |
download | hakyll-ffbce966075d258b16b44e6856333ef41e4487f4.tar.gz |
Throw an error in case of duplicate compilers
Diffstat (limited to 'src/Hakyll/Core/Rules/Internal.hs')
-rw-r--r-- | src/Hakyll/Core/Rules/Internal.hs | 22 |
1 files changed, 17 insertions, 5 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 |