Error in rendering template, can't figure it out

I’m building a new template, and when I’m trying to build I’m gettings this nasty error:

Building sites … ERROR 2018/06/05 03:37:29 Error while rendering "taxonomy" in "": template: theme/_default/list.html:39:18: executing "theme/_default/list.html" at <after 1 .Data.Pages....>: error calling after: no items left
ERROR 2018/06/05 03:37:29 Error while rendering "home" in "": template: theme/_default/list.html:39:18: executing "theme/_default/list.html" at <after 1 .Data.Pages....>: error calling after: no items left
ERROR 2018/06/05 03:37:29 Error while rendering "taxonomyTerm" in "": template: theme/_default/list.html:39:18: executing "theme/_default/list.html" at <after 1 .Data.Pages....>: error calling after: no items left
ERROR 2018/06/05 03:37:29 Error while rendering "section" in "": template: theme/_default/list.html:39:18: executing "theme/_default/list.html" at <after 1 .Data.Pages....>: error calling after: no items left
Total in 439 ms
Error: Error building site: logged 4 error(s)

This is the 39th line on list.html which is causing error:

{{ range first 30 (after 1 .Data.Pages.ByPublishDate.Reverse) }}

Interesting enough, if I remove after 1 making it

{{ range first 30 (.Data.Pages.ByPublishDate.Reverse) }}

Everything builds!

Building sites …
                   | EN
+------------------+-----+
  Pages            |  21
  Paginator pages  |   0
  Non-page files   |   0
  Static files     | 105
  Processed images |   0
  Aliases          |   0
  Sitemaps         |   1
  Cleaned          |   0

Total in 164 ms

No matter what, I couldn’t figure it out why it has problems with after 1.
Any help would be appreciated.

Version Details:
Hugo Static Site Generator v0.41 windows/amd64 BuildDate: 2018-05-25T16:57:53Z
GOOS=“windows”
GOARCH=“amd64”
GOVERSION=“go1.10.1”

Update 2:
Another very interesting observation:
1- Remove the after 1 making it

{{ range first 30 (.Data.Pages.ByPublishDate.Reverse) }}

Now I build with --watch switch.
Then as hugo is watching, I simply add the remove part, after 1, again.
hugo automatically picks up the change and everything builds correctly!
Can’t understand why.

You need to share the source of your Hugo project for people in this forum to see what’s going on.

If you cannot share it then clone your project with some dummy content.

Apparently, the build fails since the “.Data.Pages.ByPublishDate.Reverse” array can theoretically have no items. If it’s length is 0, then the “after” function will return an error, this is detected by the compiler and it stops the build. For it to build with no errors, you need to wrap the “range” inside an “if” statement that assures the array is greater than the index offset of the “after” function, like this:

{{ if gt (len .Data.Pages.ByPublishDate.Reverse) 1}}
    {{ range first 30 (after 1 .Data.Pages.ByPublishDate.Reverse) }}
    <html>
    {{ end }}
{{ end }}