shithub: hugo

Download patch

ref: 9f74dc2a52b6f568b5a060b7a4be47196804b01f
parent: d1661b823af25c50d3bbe5366ea40a3cdd52e237
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Oct 22 12:47:23 EDT 2018

hugolib: Improve errors in /data handlling

See #5324

--- a/hugofs/rootmapping_fs.go
+++ b/hugofs/rootmapping_fs.go
@@ -101,7 +101,14 @@
 		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 @@
 // 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
--- a/hugofs/rootmapping_fs_test.go
+++ b/hugofs/rootmapping_fs_test.go
@@ -50,6 +50,7 @@
 	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)
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -28,6 +28,10 @@
 	"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 @@
 
 	if len(dataChanged) > 0 {
 		if err := s.readDataFromSourceFS(); err != nil {
-			s.Log.ERROR.Println(err)
+			return whatChanged{}, err
 		}
 	}
 
@@ -884,8 +888,14 @@
 
 	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 {