diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-05-12 11:43:20 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-05-14 13:40:56 +0200 |
commit | 5c96bda70a7afb2ce97cbb3cd70c64fc8cb94446 (patch) | |
tree | 394a557b0dc7db1f6753cf2a09e8cb0577f18442 /hugolib/page.go | |
parent | 4a96df96d958a8ce122f103c4b417eaba52e6cb1 (diff) | |
download | hugo-5c96bda70a7afb2ce97cbb3cd70c64fc8cb94446.tar.gz hugo-5c96bda70a7afb2ce97cbb3cd70c64fc8cb94446.zip |
errors: Misc improvements
* Redo the server error template
* Always add the content file context if relevant
* Remove some now superflous error string matching
* Move the server error template to _server/error.html
* Add file context (with position) to codeblock render blocks
* Improve JS build errors
Fixes #9892
Fixes #9891
Fixes #9893
Diffstat (limited to 'hugolib/page.go')
-rw-r--r-- | hugolib/page.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/hugolib/page.go b/hugolib/page.go index 4faefa3cc..e9f937105 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -572,25 +572,23 @@ func (p *pageState) wrapError(err error) error { filename := p.File().Filename() - if ferr := herrors.UnwrapFileError(err); ferr != nil { + // Check if it's already added. + for _, ferr := range herrors.UnwrapFileErrors(err) { errfilename := ferr.Position().Filename - if ferr.ErrorContext() != nil || errfilename == "" || !(errfilename == pageFileErrorName || filepath.IsAbs(errfilename)) { - return err - } - if filepath.IsAbs(errfilename) { - filename = errfilename - } - f, ferr2 := p.s.SourceSpec.Fs.Source.Open(filename) - if ferr2 != nil { + if errfilename == filename { + if ferr.ErrorContext() == nil { + f, ioerr := p.s.SourceSpec.Fs.Source.Open(filename) + if ioerr != nil { + return err + } + defer f.Close() + ferr.UpdateContent(f, nil) + } return err } - defer f.Close() - pos := ferr.Position() - pos.Filename = filename - return ferr.UpdatePosition(pos).UpdateContent(f, herrors.SimpleLineMatcher) } - return herrors.NewFileErrorFromFile(err, filename, filename, p.s.SourceSpec.Fs.Source, herrors.SimpleLineMatcher) + return herrors.NewFileErrorFromFile(err, filename, filename, p.s.SourceSpec.Fs.Source, herrors.NopLineMatcher) } @@ -644,8 +642,10 @@ Loop: m, err := metadecoders.Default.UnmarshalToMap(it.Val, f) if err != nil { if fe, ok := err.(herrors.FileError); ok { - // Offset the starting position of front matter. pos := fe.Position() + // Apply the error to the content file. + pos.Filename = p.File().Filename() + // Offset the starting position of front matter. offset := iter.LineNumber() - 1 if f == metadecoders.YAML { offset -= 1 @@ -788,7 +788,7 @@ func (p *pageState) outputFormat() (f output.Format) { func (p *pageState) parseError(err error, input []byte, offset int) error { pos := p.posFromInput(input, offset) - return herrors.NewFileError("page.md", err).UpdatePosition(pos) + return herrors.NewFileError(p.File().Filename(), err).UpdatePosition(pos) } func (p *pageState) pathOrTitle() string { |