hugolib: Improve errors in /data handlling

See #5324
This commit is contained in:
Bjørn Erik Pedersen
2018-10-22 16:47:23 +02:00
parent d1661b823a
commit 9f74dc2a52
3 changed files with 26 additions and 5 deletions

View File

@@ -28,6 +28,10 @@ import (
"strings"
"time"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/common/herrors"
_errors "github.com/pkg/errors"
"github.com/gohugoio/hugo/common/maps"
@@ -776,7 +780,7 @@ func (s *Site) processPartial(events []fsnotify.Event) (whatChanged, error) {
if len(dataChanged) > 0 {
if err := s.readDataFromSourceFS(); err != nil {
s.Log.ERROR.Println(err)
return whatChanged{}, err
}
}
@@ -884,8 +888,14 @@ func (s *Site) handleDataFile(r source.ReadableFile) error {
data, err := s.readData(r)
if err != nil {
s.Log.ERROR.Printf("Failed to read data from %s: %s", filepath.Join(r.Path(), r.LogicalName()), err)
return nil
realFilename := r.FileInfo().(hugofs.RealFilenameInfo).RealFilename()
err, _ = herrors.WithFileContextForFile(
_errors.Wrapf(err, "failed to read data file"),
realFilename,
realFilename,
s.SourceSpec.Fs.Source,
herrors.SimpleLineMatcher)
return err
}
if data == nil {