summaryrefslogtreecommitdiff
path: root/src/Text/Hakyll/Internal
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-08-06 12:50:59 +0200
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-08-06 12:50:59 +0200
commitd0a9d010629566f39b012848a1b45fdf93f6bc33 (patch)
tree3765a906882971c8461d8c17bc2c3648a89cb65e /src/Text/Hakyll/Internal
parenta09a27027a1e0ae56bc9c0ec8053cae20b8ebf69 (diff)
downloadhakyll-d0a9d010629566f39b012848a1b45fdf93f6bc33.tar.gz
Readable errors when hamlet parsing fails
Diffstat (limited to 'src/Text/Hakyll/Internal')
-rw-r--r--src/Text/Hakyll/Internal/Template/Hamlet.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/Text/Hakyll/Internal/Template/Hamlet.hs b/src/Text/Hakyll/Internal/Template/Hamlet.hs
index 3bd9bb5..458ab35 100644
--- a/src/Text/Hakyll/Internal/Template/Hamlet.hs
+++ b/src/Text/Hakyll/Internal/Template/Hamlet.hs
@@ -6,13 +6,14 @@ module Text.Hakyll.Internal.Template.Hamlet
, fromHamletRT
) where
+import Control.Exception (try)
import Control.Monad.Trans (liftIO)
import System.FilePath (takeExtension)
import Text.Hamlet.RT
import Text.Hakyll.Internal.Template.Template
-import Text.Hakyll.HakyllMonad (Hakyll, askHakyll, hamletSettings)
+import Text.Hakyll.HakyllMonad (Hakyll, askHakyll, hamletSettings, logHakyll)
-- | Determine if a file is a hamlet template by extension.
--
@@ -26,7 +27,17 @@ readHamletRT :: FilePath -- ^ Filename of the template
readHamletRT fileName = do
settings <- askHakyll hamletSettings
string <- liftIO $ readFile fileName
- liftIO $ parseHamletRT settings string
+ result <- liftIO $ try $ parseHamletRT settings string
+ case result of
+ Left (HamletParseException s) -> error' s
+ Left (HamletUnsupportedDocException d) -> error' $ show d
+ Left (HamletRenderException s) -> error' s
+ Right x -> return x
+ where
+ error' s = do
+ logHakyll $ "Parse of hamlet file " ++ fileName ++ " failed."
+ logHakyll s
+ error "Parse failed."
-- | Convert a 'HamletRT' to a 'Template'
--