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
27 changed files with 600 additions and 204 deletions

View File

@@ -209,3 +209,53 @@ TS2: {{ template "print" $ts2 }}
function greeter(person) {
`)
}
func TestBuildError(t *testing.T) {
c := qt.New(t)
filesTemplate := `
-- config.toml --
disableKinds=["page", "section", "taxonomy", "term", "sitemap", "robotsTXT"]
-- assets/js/main.js --
// A comment.
import { hello1, hello2 } from './util1';
hello1();
hello2();
-- assets/js/util1.js --
/* Some
comments.
*/
import { hello3 } from './util2';
export function hello1() {
return 'abcd';
}
export function hello2() {
return hello3();
}
-- assets/js/util2.js --
export function hello3() {
return 'efgh';
}
-- layouts/index.html --
{{ $js := resources.Get "js/main.js" | js.Build }}
JS Content:{{ $js.Content }}:End:
`
c.Run("Import from main not found", func(c *qt.C) {
c.Parallel()
files := strings.Replace(filesTemplate, "import { hello1, hello2 }", "import { hello1, hello2, FOOBAR }", 1)
b, err := hugolib.NewIntegrationTestBuilder(hugolib.IntegrationTestConfig{T: c, NeedsOsFS: true, TxtarString: files}).BuildE()
b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, `main.js:2:25": No matching export`)
})
c.Run("Import from import not found", func(c *qt.C) {
c.Parallel()
files := strings.Replace(filesTemplate, "import { hello3 } from './util2';", "import { hello3, FOOBAR } from './util2';", 1)
b, err := hugolib.NewIntegrationTestBuilder(hugolib.IntegrationTestConfig{T: c, NeedsOsFS: true, TxtarString: files}).BuildE()
b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, `util1.js:4:17": No matching export in`)
})
}