hugo/content/en/functions/errorf.md
Bjørn Erik Pedersen 7eb0e10a80 Squashed 'docs/' changes from 710856e5a..6ebb5dad9
6ebb5dad9 Remove file
27cc23ef4 Hugo 0.84.4
94dccbfa4 Merge branch 'tempv0.84.4'
e9d8b61fb releaser: Add release notes to /docs for release of 0.84.4
51e472005 Improve readability of examples on shortcode templates page
0aef26479 Fix lookup order typos (#1484)
534a527fe Fix two typos (#1483)
394aabd5a Higo "0.84.3
03ee92c1c Merge branch 'tempv0.84.3'
96a8be0f1 releaser: Add release notes to /docs for release of 0.84.3
9a770323f Update index.md
7f65cfcbe Hugo 0.84.2
444422515 releaser: Add release notes to /docs for release of 0.84.2
a2f29c5d8 modules: Add module.import.noMounts config
e00e4a7e7 releaser: Add release notes to /docs for release of 0.84.2
af04b53b3 modules: Add module.import.noMounts config
f7d5669c7 Remove Appernetic (#1481)
14f8d4029 Clarify interaction of sections and top-level leaf bundles
d140b6a62 Update lookup-order.md
399904959 Update shortcode-templates.md
e78aa4865 Hugo 0.84.1
35d7c1c22 Merge branch 'tempv0.84.1'
a6be65b0d releaser: Add release notes to /docs for release of 0.84.1
7b3b3ca45 Hugo 0.84.0 News Grammar fixes
cbc23bf5a Remove trailing newlines
69349198d Fix erroridf docs
dbc1157c1 Fix missing deep

git-subtree-dir: docs
git-subtree-split: 6ebb5dad9a87655196c0990d88d50a2248df5c54
2021-07-04 16:34:26 +02:00

1.4 KiB

title description date publishdate lastmod categories menu keywords signature workson hugoversion relatedfuncs deprecated
errorf and warnf Log ERROR or WARNING from the templates. 2017-09-30 2017-09-30 2017-09-30
functions
docs
parent
functions
strings
log
error
errorf FORMAT INPUT
printf
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).

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.

{{ errorf "Failed to handle page %q" .Path }}
{{ warnf "You should update the shortcodes in %q" .Path }}

Note that errorf, erroridf, and warnf support all the formatting verbs of the fmt package.

Suppress errors

Sometimes it may make sense to let the user suppress an ERROR and make the build succeed.

You can do this by using the erroridf function. This functions takes an error ID as the first argument.

{{ erroridf "my-custom-error" "You should consider fixing this." }}

This will produce:

ERROR 2021/06/07 17:47:38 You should consider fixing this.
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
ignoreErrors = ["my-custom-error"]