hugolib: Continue the file context/line number errors work

See #5324
This commit is contained in:
Bjørn Erik Pedersen
2018-10-21 12:20:21 +02:00
parent 7930d2132a
commit d1661b823a
23 changed files with 444 additions and 236 deletions

View File

@@ -30,7 +30,6 @@ import (
_errors "github.com/pkg/errors"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/publisher"
"github.com/gohugoio/hugo/resource"
@@ -1552,7 +1551,7 @@ func (s *Site) preparePages() error {
}
}
return s.pickOneAndLogTheRest(errors)
return s.owner.pickOneAndLogTheRest(errors)
}
func (s *Site) errorCollator(results <-chan error, errs chan<- error) {
@@ -1561,45 +1560,11 @@ func (s *Site) errorCollator(results <-chan error, errs chan<- error) {
errors = append(errors, e)
}
errs <- s.pickOneAndLogTheRest(errors)
errs <- s.owner.pickOneAndLogTheRest(errors)
close(errs)
}
func (s *Site) pickOneAndLogTheRest(errors []error) error {
if len(errors) == 0 {
return nil
}
var i int
for j, err := range errors {
// If this is in server mode, we want to return an error to the client
// with a file context, if possible.
if herrors.UnwrapErrorWithFileContext(err) != nil {
i = j
break
}
}
// Log the rest, but add a threshold to avoid flooding the log.
const errLogThreshold = 5
for j, err := range errors {
if j == i {
continue
}
if j >= errLogThreshold {
break
}
s.Log.ERROR.Println(err)
}
return errors[i]
}
func (s *Site) appendThemeTemplates(in []string) []string {
if !s.PathSpec.ThemeSet() {
return in