@@ -167,7 +167,7 @@ loadTemplate name logIt = do
167167
168168-- | Apply and unpack a template into a directory.
169169applyTemplate
170- :: (MonadIO m , MonadThrow m , MonadReader r m , HasConfig r , MonadLogger m )
170+ :: (MonadIO m , MonadThrow m , MonadCatch m , MonadReader r m , HasConfig r , MonadLogger m )
171171 => PackageName
172172 -> TemplateName
173173 -> Map Text Text
@@ -189,9 +189,14 @@ applyTemplate project template nonceParams dir templateText = do
189189 unless (S. null missingKeys)
190190 ($ logInfo (T. pack (show (MissingParameters project template missingKeys (configUserConfigPath config)))))
191191 files :: Map FilePath LB. ByteString <-
192- execWriterT $
193- yield (T. encodeUtf8 (LT. toStrict applied)) $$
194- unpackTemplate receiveMem id
192+ catch (execWriterT $
193+ yield (T. encodeUtf8 (LT. toStrict applied)) $$
194+ unpackTemplate receiveMem id
195+ )
196+ (\ (e :: ProjectTemplateException ) ->
197+ throwM (InvalidTemplate template (show e)))
198+ when (M. null files) $
199+ throwM (InvalidTemplate template " Template does not contain any files" )
195200 liftM
196201 M. fromList
197202 (mapM
@@ -319,6 +324,7 @@ data NewException
319324 | BadTemplatesJSON ! String ! LB. ByteString
320325 | AlreadyExists ! (Path Abs Dir )
321326 | MissingParameters ! PackageName ! TemplateName ! (Set String ) ! (Path Abs File )
327+ | InvalidTemplate ! TemplateName ! String
322328 deriving (Typeable )
323329
324330instance Exception NewException
@@ -373,3 +379,7 @@ instance Show NewException where
373379 (\ key ->
374380 " -p \" " <> key <> " :value\" " )
375381 (S. toList missingKeys))]
382+ show (InvalidTemplate name why) =
383+ " The template \" " <> T. unpack (templateName name) <>
384+ " \" is invalid and could not be used. " <>
385+ " The error was: \" " <> why <> " \" "
0 commit comments