ref: 50cc7fe54580018239ea95aafe67f6a158cdcc9f
parent: 1773d71d5b40f5a6a14edca417d2818607a499f1
author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
date: Sat Dec 21 05:26:14 EST 2019
tpl: Do not return any value in errorf Fixes #6653
--- a/docs/content/en/functions/errorf.md
+++ b/docs/content/en/functions/errorf.md
@@ -14,7 +14,7 @@
hugoversion:
relatedfuncs: [printf]
deprecated: false
-aliases: []
+aliases: [/functions/errorf]
---
`errorf` or `warnf` will evaluate a format string, then output the result to the ERROR or WARNING log (and only once per error message to avoid flooding the log).
@@ -21,7 +21,7 @@
Any ERROR will also cause the build to fail (the `hugo` command will `exit -1`).
-Note that the WARNING will only be printed to the console.
+Both functions return an empty string, so the messages are only printed to the console.
```
{{ errorf "Failed to handle page %q" .Path }}
--- a/tpl/fmt/fmt.go
+++ b/tpl/fmt/fmt.go
@@ -51,11 +51,11 @@
return _fmt.Sprintln(a...)
}
-// Errorf formats according to a format specifier and returns the string as a
-// value that satisfies error.
+// Errorf formats according to a format specifier and logs an ERROR.
+// It returns an empty string.
func (ns *Namespace) Errorf(format string, a ...interface{}) string {
ns.errorLogger.Printf(format, a...)
- return _fmt.Sprintf(format, a...)
+ return ""
}
// Warnf formats according to a format specifier and logs a WARNING.
--- a/tpl/fmt/init.go
+++ b/tpl/fmt/init.go
@@ -53,7 +53,7 @@
ns.AddMethodMapping(ctx.Errorf,
[]string{"errorf"},
[][2]string{
- {`{{ errorf "%s." "failed" }}`, `failed.`},
+ {`{{ errorf "%s." "failed" }}`, ``},
},
)