hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 9f74dc2a52b6f568b5a060b7a4be47196804b01f
parent d1661b823af25c50d3bbe5366ea40a3cdd52e237
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Mon, 22 Oct 2018 16:47:23 +0200

hugolib: Improve errors in /data handlling

See #5324

Diffstat:
Mhugofs/rootmapping_fs.go | 14++++++++++++--
Mhugofs/rootmapping_fs_test.go | 1+
Mhugolib/site.go | 16+++++++++++++---
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go
@@ -101,7 +101,14 @@ func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error) {
 		return newRootMappingDirFileInfo(name), nil
 	}
 	realName := fs.realName(name)
-	return fs.Fs.Stat(realName)
+
+	fi, err := fs.Fs.Stat(realName)
+	if rfi, ok := fi.(RealFilenameInfo); ok {
+		return rfi, err
+	}
+
+	return &realFilenameInfo{FileInfo: fi, realFilename: realName}, err
+
 }
 
 func (fs *RootMappingFs) isRoot(name string) bool {
@@ -126,12 +133,15 @@ func (fs *RootMappingFs) Open(name string) (afero.File, error) {
 // It attempts to use Lstat if supported or defers to the os.  In addition to
 // the FileInfo, a boolean is returned telling whether Lstat was called.
 func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
+
 	if fs.isRoot(name) {
 		return newRootMappingDirFileInfo(name), false, nil
 	}
 	name = fs.realName(name)
+
 	if ls, ok := fs.Fs.(afero.Lstater); ok {
-		return ls.LstatIfPossible(name)
+		fi, b, err := ls.LstatIfPossible(name)
+		return &realFilenameInfo{FileInfo: fi, realFilename: name}, b, err
 	}
 	fi, err := fs.Stat(name)
 	return fi, false, err
diff --git a/hugofs/rootmapping_fs_test.go b/hugofs/rootmapping_fs_test.go
@@ -50,6 +50,7 @@ func TestRootMappingFsDirnames(t *testing.T) {
 	fif, err := rfs.Stat(filepath.Join("cf2", testfile))
 	assert.NoError(err)
 	assert.Equal("myfile.txt", fif.Name())
+	assert.Equal("f2t/myfile.txt", fif.(RealFilenameInfo).RealFilename())
 
 	root, err := rfs.Open(filepathSeparator)
 	assert.NoError(err)
diff --git a/hugolib/site.go b/hugolib/site.go
@@ -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 {