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
This commit is contained in:
Bjørn Erik Pedersen 2022-05-12 11:43:20 +02:00
parent 4a96df96d9
commit 5c96bda70a
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
27 changed files with 600 additions and 204 deletions

View file

@ -22,7 +22,6 @@ import (
jww "github.com/spf13/jwalterweatherman"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/hugolib"
)
@ -116,7 +115,7 @@ func TestTransformPostCSS(t *testing.T) {
b.AssertFileContent("public/index.html", `
Styles RelPermalink: /css/styles.css
Styles Content: Len: 770875|
Styles Content: Len: 770917|
`)
}
@ -138,13 +137,6 @@ func TestTransformPostCSSError(t *testing.T) {
}).BuildE()
s.AssertIsFileError(err)
fe := herrors.UnwrapFileError(err)
pos := fe.Position()
c.Assert(strings.TrimPrefix(pos.Filename, s.H.WorkingDir), qt.Equals, filepath.FromSlash("/assets/css/components/a.css"))
c.Assert(pos.LineNumber, qt.Equals, 4)
errctx := fe.ErrorContext()
c.Assert(errctx, qt.IsNotNil)
c.Assert(errctx.Lines, qt.DeepEquals, []string{"/* Another comment. */", "class-in-a {", "\t@apply foo;", "}", ""})
c.Assert(errctx.ChromaLexer, qt.Equals, "css")
c.Assert(err.Error(), qt.Contains, "a.css:4:2")
}