diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-04-04 13:32:29 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-04-04 15:12:30 +0200 |
commit | 868f89d5c69c1f028b4d8900ccddd671a8d1922c (patch) | |
tree | 2493e6e289a179ef254a1aa81edb8cdf875ff57f /hugolib | |
parent | 04d80e6e8725dd9d1ee76d7615ae312f995cd7bc (diff) |
hugolib: Improve render error handling
Catch and return the "template not found" error earlier.
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/site.go | 48 | ||||
-rw-r--r-- | hugolib/site_render.go | 11 |
2 files changed, 14 insertions, 45 deletions
diff --git a/hugolib/site.go b/hugolib/site.go index 722e14881..7b5d0d156 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1845,10 +1845,9 @@ func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layout defer bp.PutBuffer(renderBuffer) renderBuffer.WriteString("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n") - err := s.renderForLayouts(name, d, renderBuffer, layouts...) - - if err != nil { - return err + if err := s.renderForLayouts(name, d, renderBuffer, layouts...); err != nil { + helpers.DistinctWarnLog.Println(err) + return nil } outBuffer := bp.GetBuffer() @@ -1875,10 +1874,9 @@ func (s *Site) renderAndWritePage(name string, dest string, p *PageOutput, layou renderBuffer := bp.GetBuffer() defer bp.PutBuffer(renderBuffer) - err := s.renderForLayouts(p.Kind, p, renderBuffer, layouts...) - - if err != nil { - return err + if err := s.renderForLayouts(p.Kind, p, renderBuffer, layouts...); err != nil { + helpers.DistinctWarnLog.Println(err) + return nil } outBuffer := bp.GetBuffer() @@ -1916,46 +1914,16 @@ func (s *Site) renderAndWritePage(name string, dest string, p *PageOutput, layou transformer := transform.NewChain(transformLinks...) transformer.Apply(outBuffer, renderBuffer, path) - if outBuffer.Len() == 0 { - - s.Log.WARN.Printf("%s is rendered empty\n", dest) - if dest == "/" { - debugAddend := "" - if !s.Cfg.GetBool("verbose") { - debugAddend = "* For more debugging information, run \"hugo -v\"" - } - helpers.DistinctFeedbackLog.Printf(`============================================================= -Your rendered home page is blank: /index.html is zero-length - * Did you specify a theme on the command-line or in your - %q file? (Current theme: %q) - %s -=============================================================`, - filepath.Base(viper.ConfigFileUsed()), - s.Cfg.GetString("theme"), - debugAddend) - } - - // Avoid writing empty files to disk. - return nil - - } - - if err = s.publish(dest, outBuffer); err != nil { - return err - } - - return nil + return s.publish(dest, outBuffer) } func (s *Site) renderForLayouts(name string, d interface{}, w io.Writer, layouts ...string) error { templ := s.findFirstTemplate(layouts...) if templ == nil { - helpers.DistinctWarnLog.Printf("[%s] Unable to locate layout for %s: %s\n", s.Language.Lang, name, layouts) - return nil + return fmt.Errorf("[%s] Unable to locate layout for %q: %s\n", s.Language.Lang, name, layouts) } if err := templ.Execute(w, d); err != nil { - // Behavior here should be dependent on if running in server or watch mode. helpers.DistinctErrorLog.Printf("Error while rendering %q: %s", name, err) if !s.running() && !testMode { diff --git a/hugolib/site_render.go b/hugolib/site_render.go index b27bf9752..de8b28723 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -19,6 +19,8 @@ import ( "sync" "time" + "github.com/spf13/hugo/helpers" + "github.com/spf13/hugo/output" bp "github.com/spf13/hugo/bufferpool" @@ -333,13 +335,12 @@ func (s *Site) renderRobotsTXT() error { rLayouts := []string{"robots.txt", "_default/robots.txt", "_internal/_default/robots.txt"} outBuffer := bp.GetBuffer() defer bp.PutBuffer(outBuffer) - err := s.renderForLayouts("robots", n, outBuffer, s.appendThemeTemplates(rLayouts)...) - - if err == nil { - err = s.publish("robots.txt", outBuffer) + if err := s.renderForLayouts("robots", n, outBuffer, s.appendThemeTemplates(rLayouts)...); err != nil { + helpers.DistinctWarnLog.Println(err) + return nil } - return err + return s.publish("robots.txt", outBuffer) } // renderAliases renders shell pages that simply have a redirect in the header. |