hakyll icon indicating copy to clipboard operation
hakyll copied to clipboard

runtime errors in listFields associated to the wrong context

Open damiencourousse opened this issue 5 years ago • 1 comments

listField has type signature String -> Context a -> Compiler [Item a] -> Context b. If a runtime error is met by the compiler (Compiler [Item a]), the error message seems to be related to the built context (Context b) instead of the context used by the compiler (Context a), which is confusing.
Here is an illustration below:

Suppose that I use the following code snippet:

    match "images/*" $ do
      route idRoute
      compile copyFileCompiler

    create ["images.html"] $ do
      route idRoute
      compile $ do
        photos <- loadAll "images/*"
        let imageCtx :: Context CopyFile
            imageCtx = urlField "url"
                       <> dateField "date" "%A, %e %B %Y"
            photosCtx :: Context String
            photosCtx = constField "title" "expressions urbaines"
                        <> listField "photos" imageCtx (loadAll "images/*")
                        <> defaultContext

If imageCtx does not carry a date field, a runtime error message is delivered when building the site because of the use of recentFirst in the compiler used by listField. The error message is currently:

  [ERROR] Missing field $photos$ in context for item images.html

This error message makes it hard to understand that, actually, the context imageCtx does not properly define the dateField required by recentFirst.

damiencourousse avatar Jul 30 '19 14:07 damiencourousse

I'll have to try this with #462

bergus avatar Aug 03 '19 21:08 bergus