@@ -6,13 +6,14 @@ module Text.Hakyll.Internal.Template.Hamlet
66 , fromHamletRT
77 ) where
88
9+import Control.Exception (try)
910import Control.Monad.Trans (liftIO)
1011import System.FilePath (takeExtension)
1112
1213import Text.Hamlet.RT
1314
1415import Text.Hakyll.Internal.Template.Template
15−import Text.Hakyll.HakyllMonad (Hakyll, askHakyll, hamletSettings)
16+import Text.Hakyll.HakyllMonad (Hakyll, askHakyll, hamletSettings, logHakyll)
1617
1718-- | Determine if a file is a hamlet template by extension.
1819--
@@ -26,7 +27,17 @@ readHamletRT :: FilePath -- ^ Filename of the template
2627readHamletRT fileName = do
2728 settings <- askHakyll hamletSettings
2829 string <- liftIO $ readFile fileName
29− liftIO $ parseHamletRT settings string
30+ result <- liftIO $ try $ parseHamletRT settings string
31+ case result of
32+ Left (HamletParseException s) -> error' s
33+ Left (HamletUnsupportedDocException d) -> error' $ show d
34+ Left (HamletRenderException s) -> error' s
35+ Right x -> return x
36+ where
37+ error' s = do
38+ logHakyll $ "Parse of hamlet file " ++ fileName ++ " failed."
39+ logHakyll s
40+ error "Parse failed."
3041
3142-- | Convert a 'HamletRT' to a 'Template'
3243--