diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-22 17:42:06 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-10-22 20:46:14 +0200 |
commit | 2bf686ee217808186385bfcf6156f15bbdb33651 (patch) | |
tree | 6184e03782e693209828af09fef213d9a8309dcb /hugolib | |
parent | 9f74dc2a52b6f568b5a060b7a4be47196804b01f (diff) |
hugolib: Improve errors in /i18n handlling
See #5324
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/site.go | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/hugolib/site.go b/hugolib/site.go index e3f6d8f8c..127b143e5 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -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 { |