Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error messages #722

Merged
merged 22 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2b87d13
Better error messages for context fields
bergus Aug 4, 2016
8ac7949
Better error messages for template applications
bergus Aug 4, 2016
9ec43a6
Better error messages for template parsing
bergus Aug 4, 2016
7031661
docs, docs, docs! Full coverage for Template and Context
bergus Aug 5, 2016
f98a220
Less debug messages from templates
bergus Aug 11, 2016
0ec007e
Better error messages from Alternative fails
bergus Aug 17, 2016
458e78d
Better error messages for templates
bergus Aug 17, 2016
dd68b2e
Merge branch 'master' into error-messages
bergus Mar 8, 2018
f546381
test case for mismatched template syntax
bergus Mar 8, 2018
7f1b00e
Cleanup of CompilerResult, use extra data type instead of Verbosity
bergus Mar 10, 2018
1e04f93
Better names, some minor simplifications
bergus Mar 10, 2018
2f6ef3a
Added useful exports and improved documenttion
bergus Mar 15, 2018
c098216
Merge remote-tracking branch 'origin/master'
bergus Mar 27, 2018
e523fb7
better error messages for file system operations
bergus Mar 25, 2018
f6af7d4
more precise error messages for template application
bergus Mar 19, 2018
e263ccf
fix documentation syntax
bergus Apr 9, 2018
9108ec5
Merge branch 'bergus/error-messages' into error-messages
jaspervdj Aug 20, 2019
b2eba3c
Renaming, use NonEmpty for compilation failures
jaspervdj Aug 20, 2019
1afc807
More renaming, fix tests
jaspervdj Aug 20, 2019
c7c581c
Fix some PR comments
jaspervdj Aug 27, 2019
588d6b7
Fix feed template types
jaspervdj Aug 27, 2019
f96b99e
Explicitly embed templates
jaspervdj Aug 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions hakyll.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,26 @@ Library
data-default >= 0.4 && < 0.8,
deepseq >= 1.3 && < 1.5,
directory >= 1.0 && < 1.4,
file-embed >= 0.0.10.1 && < 0.0.12,
filepath >= 1.0 && < 1.5,
lrucache >= 1.1.1 && < 1.3,
mtl >= 1 && < 2.3,
network-uri >= 2.6 && < 2.7,
optparse-applicative >= 0.12 && < 0.15,
parsec >= 3.0 && < 3.2,
process >= 1.6 && < 1.7,
random >= 1.0 && < 1.2,
regex-tdfa >= 1.1 && < 1.3,
resourcet >= 1.1 && < 1.3,
scientific >= 0.3.4 && < 0.4,
tagsoup >= 0.13.1 && < 0.15,
template-haskell >= 2.14 && < 2.15,
text >= 0.11 && < 1.3,
time >= 1.8 && < 1.10,
time-locale-compat >= 0.1 && < 0.2,
unordered-containers >= 0.2 && < 0.3,
vector >= 0.11 && < 0.13,
yaml >= 0.8.11 && < 0.12,
optparse-applicative >= 0.12 && < 0.15,
file-embed >= 0.0.10.1 && < 0.0.12
yaml >= 0.8.11 && < 0.12

If flag(previewServer)
Build-depends:
Expand Down
37 changes: 35 additions & 2 deletions lib/Hakyll/Core/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ module Hakyll.Core.Compiler
, cached
, unsafeCompiler
, debugCompiler
, noResult
, withErrorMessage
) where


--------------------------------------------------------------------------------
import Control.Monad (when, unless)
import Control.Monad (unless, when, (>=>))
import Data.Binary (Binary)
import Data.ByteString.Lazy (ByteString)
import qualified Data.List.NonEmpty as NonEmpty
import Data.Typeable (Typeable)
import System.Environment (getProgName)
import System.FilePath (takeExtension)
Expand Down Expand Up @@ -62,6 +65,7 @@ getUnderlyingExtension = takeExtension . toFilePath <$> getUnderlying


--------------------------------------------------------------------------------
-- | Create an item from the underlying identifier and a given value.
makeItem :: a -> Compiler (Item a)
makeItem x = do
identifier <- getUnderlying
Expand Down Expand Up @@ -141,6 +145,10 @@ saveSnapshot snapshot item = do


--------------------------------------------------------------------------------
-- | Turn on caching for a compilation value to avoid recomputing it
-- on subsequent Hakyll runs.
-- The storage key consists of the underlying identifier of the compiled
-- ressource and the given name.
cached :: (Binary a, Typeable a)
=> String
-> Compiler a
Expand Down Expand Up @@ -177,12 +185,37 @@ cached name compiler = do


--------------------------------------------------------------------------------
-- | Run an IO computation without dependencies in a Compiler
unsafeCompiler :: IO a -> Compiler a
unsafeCompiler = compilerUnsafeIO


--------------------------------------------------------------------------------
-- | Compiler for debugging purposes
-- | Fail so that it is treated as non-defined in an @\$if()\$@ branching
-- "Hakyll.Web.Template" macro, and alternative
-- 'Hakyll.Web.Template.Context.Context's are tried
--
-- @since 4.13.0
noResult :: String -> Compiler a
noResult = compilerNoResult . return
jaspervdj marked this conversation as resolved.
Show resolved Hide resolved


--------------------------------------------------------------------------------
-- | Prepend an error line to the error, if there is one. This allows you to
-- add helpful context to error messages.
--
-- @since 4.13.0
withErrorMessage :: String -> Compiler a -> Compiler a
withErrorMessage x = do
compilerTry >=> either (compilerResult . CompilerError . prepend) return
where
prepend (CompilationFailure es) = CompilationFailure (x `NonEmpty.cons` es)
prepend (CompilationNoResult es) = CompilationNoResult (x : es)


--------------------------------------------------------------------------------
-- | Compiler for debugging purposes.
-- Passes a message to the debug logger that is printed in verbose mode.
debugCompiler :: String -> Compiler ()
debugCompiler msg = do
logger <- compilerLogger <$> compilerAsk
Expand Down
Loading