This release contains some fixes and improvements related to error handling in remote lookups in resources.Get
, as introduced in Hugo 0.90.0:
- Now we will always return
nil
(never fail the build) when a resource is not found, also for remote resources (HTTP status code 404). This means that you can do{{ with $img }}{{ else }}{{/* insert a default image or something */}}{{ end }}
and similar constructs, not having to consider where the resource source lives. - Fetching resources remotely over HTTPS has a much greater chance of failing (network down, server down) than reading a file from disk (if not already cached). And having this lead to a failing build is not always optimal. This release allows you to handle/ignore these errors in the templates if needed, see details below.
The return value from resources.Get
now includes an .Err
method that will be set if the call failed. If you want to just log any error as a WARNING
you can use a construct similar to the one below.
Note that if you do not handle .Err
yourself, Hugo will fail the build the first time you start using the failed Resource
object.
Changes
- Remove the retries on error in remote resources.Get 3bc6830 @bep #9271
- Allow user to handle/ignore errors in resources.Get e4d6ec9 @bep #9259
- Make resource.Get return nil on 404 not found 6260455 @bep #9267
- Update to Go 1.17.5 c397975 @bep #9269
- Update to Go 1.17.4 and remove timeout in resources.Get 965a6cb @bep #9265