Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'

This commit is contained in:
Bjørn Erik Pedersen
2023-05-22 16:47:07 +02:00
341 changed files with 3107 additions and 4238 deletions

View File

@@ -1,19 +1,13 @@
---
title: errorf and warnf
description: Log ERROR or WARNING from the templates.
date: 2017-09-30
publishdate: 2017-09-30
lastmod: 2017-09-30
categories: [functions]
menu:
docs:
parent: "functions"
parent: functions
keywords: [strings, log, error]
signature: ["errorf FORMAT INPUT"]
workson: []
hugoversion:
relatedfuncs: [printf]
deprecated: false
---
`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).
@@ -22,11 +16,11 @@ Any ERROR will also cause the build to fail (the `hugo` command will `exit -1`).
Both functions return an empty string, so the messages are only printed to the console.
```
```go-html-template
{{ errorf "Failed to handle page %q" .Path }}
```
```
```go-html-template
{{ warnf "You should update the shortcodes in %q" .Path }}
```
@@ -38,7 +32,7 @@ Sometimes it may make sense to let the user suppress an ERROR and make the build
You can do this by using the `erroridf` function. This functions takes an error ID as the first argument.
```
```go-html-template
{{ erroridf "my-custom-error" "You should consider fixing this." }}
```