hugolib: Reset the global pages cache on server rebuilds
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 13 Jun 2018 06:57:26 +0000 (08:57 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 13 Jun 2018 10:00:30 +0000 (12:00 +0200)
In Hugo 0.42, this could lead to errors of type `runtime error: invalid memory address or nil pointer dereference` in some rare situations.

Note that this was also an issue before 0.42, but the symptom was then potentially stale list content on rebuilds on content changes.

This commit also improves the above error message.

Fixes #4845

hugolib/page_output.go
hugolib/site.go

index 132d755f2cc15f032af981163850d01134265120..c1550ccd14affc0b820e75a230721071a015c4fa 100644 (file)
@@ -141,6 +141,9 @@ func (p *PageOutput) Render(layout ...string) template.HTML {
 }
 
 func (p *Page) Render(layout ...string) template.HTML {
+       if p.mainPageOutput == nil {
+               panic(fmt.Sprintf("programming error: no mainPageOutput for %q", p.Path()))
+       }
        return p.mainPageOutput.Render(layout...)
 }
 
index 8ff724d0a0a30e1c67a44c7fbd04d09c93d41164..83121677990a697b62b55b0d4d4802212d853960 100644 (file)
@@ -1492,6 +1492,8 @@ func (s *Site) resetBuildState() {
 
        s.expiredCount = 0
 
+       spc = newPageCache()
+
        for _, p := range s.rawAllPages {
                p.subSections = Pages{}
                p.parent = nil