hugolib: Improve errors in /i18n handlling

See #5324
This commit is contained in:
Bjørn Erik Pedersen
2018-10-22 17:42:06 +02:00
parent 9f74dc2a52
commit 2bf686ee21
5 changed files with 64 additions and 20 deletions

View File

@@ -861,6 +861,24 @@ func (s *Site) loadData(fs afero.Fs) (err error) {
return
}
func (s *Site) errWithFileContext(err error, f source.File) error {
rfi, ok := f.FileInfo().(hugofs.RealFilenameInfo)
if !ok {
return err
}
realFilename := rfi.RealFilename()
err, _ = herrors.WithFileContextForFile(
err,
realFilename,
realFilename,
s.SourceSpec.Fs.Source,
herrors.SimpleLineMatcher)
return err
}
func (s *Site) handleDataFile(r source.ReadableFile) error {
var current map[string]interface{}
@@ -888,14 +906,7 @@ func (s *Site) handleDataFile(r source.ReadableFile) error {
data, err := s.readData(r)
if err != 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
return s.errWithFileContext(err, r)
}
if data == nil {