2019-10-21 04:22:28 -04:00
---
2019-12-20 14:46:17 -05:00
title: errorf and warnf
description: Log ERROR or WARNING from the templates.
2019-10-21 04:22:28 -04:00
date: 2017-09-30
publishdate: 2017-09-30
lastmod: 2017-09-30
categories: [functions]
menu:
docs:
parent: "functions"
keywords: [strings, log, error]
signature: ["errorf FORMAT INPUT"]
workson: []
hugoversion:
relatedfuncs: [printf]
deprecated: false
2019-12-21 04:26:14 -05:00
aliases: [/functions/errorf]
2019-10-21 04:22:28 -04:00
---
2019-12-20 14:46:17 -05:00
`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).
2019-10-21 04:22:28 -04:00
2019-12-20 14:46:17 -05:00
Any ERROR will also cause the build to fail (the `hugo` command will `exit -1` ).
2019-12-21 04:26:14 -05:00
Both functions return an empty string, so the messages are only printed to the console.
2019-10-21 04:22:28 -04:00
```
{{ errorf "Failed to handle page %q" .Path }}
```
2019-12-20 14:46:17 -05:00
```
{{ warnf "You should update the shortcodes in %q" .Path }}
```
Note that `errorf` and `warnf` support all the formatting verbs of the [fmt ](https://golang.org/pkg/fmt/ ) package.