summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-12 11:43:20 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-14 13:40:56 +0200
commit5c96bda70a7afb2ce97cbb3cd70c64fc8cb94446 (patch)
tree394a557b0dc7db1f6753cf2a09e8cb0577f18442 /commands
parent4a96df96d958a8ce122f103c4b417eaba52e6cb1 (diff)
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 'commands')
-rw-r--r--commands/hugo.go5
-rw-r--r--commands/server.go20
2 files changed, 17 insertions, 8 deletions
diff --git a/commands/hugo.go b/commands/hugo.go
index ada1e1cef..8dfd4b4bd 100644
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -736,10 +736,7 @@ func (c *commandeer) buildSites(noBuildLock bool) (err error) {
func (c *commandeer) handleBuildErr(err error, msg string) {
c.buildErr = err
-
- c.logger.Errorln(msg + ":\n")
- c.logger.Errorln(helpers.FirstUpper(err.Error()))
-
+ c.logger.Errorln(msg + ": " + cleanErrorLog(err.Error()))
}
func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
diff --git a/commands/server.go b/commands/server.go
index 27b12cb32..036fa9eaa 100644
--- a/commands/server.go
+++ b/commands/server.go
@@ -469,14 +469,26 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
return mu, listener, u.String(), endpoint, nil
}
-var logErrorRe = regexp.MustCompile(`(?s)ERROR \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} `)
+var (
+ logErrorRe = regexp.MustCompile(`(?s)ERROR \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} `)
+ logDuplicateTemplateExecuteRe = regexp.MustCompile(`: template: .*?:\d+:\d+: executing ".*?"`)
+ logDuplicateTemplateParseRe = regexp.MustCompile(`: template: .*?:\d+:\d*`)
+)
func removeErrorPrefixFromLog(content string) string {
return logErrorRe.ReplaceAllLiteralString(content, "")
}
+
+var logReplacer = strings.NewReplacer(
+ "can't", "can’t", // Chroma lexer does'nt do well with "can't"
+ "*hugolib.pageState", "page.Page", // Page is the public interface.
+)
+
func cleanErrorLog(content string) string {
- content = strings.ReplaceAll(content, "Rebuild failed:\n", "")
- content = strings.ReplaceAll(content, "\n", "")
+ content = strings.ReplaceAll(content, "\n", " ")
+ content = logReplacer.Replace(content)
+ content = logDuplicateTemplateExecuteRe.ReplaceAllString(content, "")
+ content = logDuplicateTemplateParseRe.ReplaceAllString(content, "")
seen := make(map[string]bool)
parts := strings.Split(content, ": ")
keep := make([]string, 0, len(parts))
@@ -515,7 +527,7 @@ func (c *commandeer) serve(s *serverCmd) error {
c: c,
s: s,
errorTemplate: func(ctx any) (io.Reader, error) {
- templ, found := c.hugo().Tmpl().Lookup("server/error.html")
+ templ, found := c.hugo().Tmpl().Lookup("_server/error.html")
if !found {
panic("template server/error.html not found")
}