🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

Commit 0292014748caae952bbc8dd6225680d83c0a5135
Parent: 143fdb3b66c85512696406fab8d3ba525bffc675
Author: mcol <mcol@posteo.net>
Date: 2021-11-25 00:05:26 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-25 00:05:26 +0000

Printy print template error messages

src/Templates.hs Modified

@@ -35,7 +35,7 @@
 import qualified Text.Ginger.AST as G
 import Text.Ginger.GVal (GVal)
 import Text.Ginger.Html (Html, htmlSource)
-import Text.Ginger.Parse (SourcePos, parseGingerFile, peErrorMessage)
+import Text.Ginger.Parse (ParserError (..), SourcePos, parseGingerFile)
 import Text.Ginger.Run (easyContext, runGingerT)
 
 import Config
@@ -108,8 +108,16 @@
     parseGingerFile includeResolver path >>= \case
         Right parsed -> return . Just . Template path $ parsed
         Left err -> do
-            putStrLn . peErrorMessage $ err
+            informError err
             return Nothing
+  where
+    -- An attempt at pretty printing the error message.
+    informError :: ParserError -> IO ()
+    informError (ParserError msg Nothing) =
+        putStr $ "Template error: " <> path <> "\n" <> indent msg
+    informError (ParserError msg (Just pos)) =
+        putStrLn $ "Template error: " <> path <> "\n" <> indent (show pos <> "\n" <> msg)
+    indent = unlines . map (mappend "    ") . lines
 
 {-
 This resolves Ginger's template includes.