hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

errorf.md (1459B)

    1 ---
    2 title: errorf and warnf
    3 description: Log ERROR or WARNING from the templates.
    4 date: 2017-09-30
    5 publishdate: 2017-09-30
    6 lastmod: 2017-09-30
    7 categories: [functions]
    8 menu:
    9   docs:
   10     parent: "functions"
   11 keywords: [strings, log, error]
   12 signature: ["errorf FORMAT INPUT"]
   13 workson: []
   14 hugoversion:
   15 relatedfuncs: [printf]
   16 deprecated: false
   17 ---
   18 
   19 `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).
   20 
   21 Any ERROR will also cause the build to fail (the `hugo` command will `exit -1`).
   22 
   23 Both functions return an empty string, so the messages are only printed to the console.
   24 
   25 ```
   26 {{ errorf "Failed to handle page %q" .Path }}
   27 ```
   28 
   29 ```
   30 {{ warnf "You should update the shortcodes in %q" .Path }}
   31 ```
   32 
   33 Note that `errorf`, `erroridf`, and `warnf` support all the formatting verbs of the [fmt](https://golang.org/pkg/fmt/) package.
   34 
   35 ## Suppress errors
   36 
   37 Sometimes it may make sense to let the user suppress an ERROR and make the build succeed.
   38 
   39 You can do this by using the `erroridf` function. This functions takes an error ID as the first argument.
   40 
   41 ```
   42 {{ erroridf "my-custom-error" "You should consider fixing this." }}
   43 ```  
   44 
   45 This will produce:
   46 
   47 ```
   48 ERROR 2021/06/07 17:47:38 You should consider fixing this.
   49 If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
   50 ignoreErrors = ["my-custom-error"]
   51 ```