Skip to content

Commit

Permalink
tpl: Do not return any value in errorf
Browse files Browse the repository at this point in the history
Fixes #6653
  • Loading branch information
bep committed Dec 21, 2019
1 parent 1773d71 commit 50cc7fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/content/en/functions/errorf.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 3 additions & 3 deletions tpl/fmt/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tpl/fmt/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
ns.AddMethodMapping(ctx.Errorf,
[]string{"errorf"},
[][2]string{
{`{{ errorf "%s." "failed" }}`, `failed.`},
{`{{ errorf "%s." "failed" }}`, ``},
},
)

Expand Down

0 comments on commit 50cc7fe

Please sign in to comment.