From d0a9d010629566f39b012848a1b45fdf93f6bc33 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Fri, 6 Aug 2010 12:50:59 +0200 Subject: Readable errors when hamlet parsing fails --- src/Text/Hakyll/Internal/Template/Hamlet.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/Text/Hakyll/Internal/Template/Hamlet.hs') 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' -- -- cgit v1.2.3