From 50cc7fe54580018239ea95aafe67f6a158cdcc9f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 21 Dec 2019 10:26:14 +0100 Subject: [PATCH] tpl: Do not return any value in errorf Fixes #6653 --- docs/content/en/functions/errorf.md | 4 ++-- tpl/fmt/fmt.go | 6 +++--- tpl/fmt/init.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/content/en/functions/errorf.md b/docs/content/en/functions/errorf.md index edc8e575..9cd7e69b 100644 --- a/docs/content/en/functions/errorf.md +++ b/docs/content/en/functions/errorf.md @@ -14,14 +14,14 @@ workson: [] 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). 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 }} diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go index 7e025865..aa6b8c1a 100644 --- a/tpl/fmt/fmt.go +++ b/tpl/fmt/fmt.go @@ -51,11 +51,11 @@ func (ns *Namespace) Println(a ...interface{}) string { 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. diff --git a/tpl/fmt/init.go b/tpl/fmt/init.go index 14568b45..6a2c9a85 100644 --- a/tpl/fmt/init.go +++ b/tpl/fmt/init.go @@ -53,7 +53,7 @@ func init() { ns.AddMethodMapping(ctx.Errorf, []string{"errorf"}, [][2]string{ - {`{{ errorf "%s." "failed" }}`, `failed.`}, + {`{{ errorf "%s." "failed" }}`, ``}, }, ) -- 2.30.2