aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/resource
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2021-12-09 16:57:05 +0100
committerBjørn Erik Pedersen <[email protected]>2021-12-10 11:10:41 +0100
commite4d6ec94b5c1ea1c670f1e7127fc20ff2371cb0b (patch)
tree89b9017705262c6c19058e7d9b2d3decb508cf90 /resources/resource
parent6260455ba73e2f2bd16b068a72e98e48b037a179 (diff)
downloadhugo-e4d6ec94b5c1ea1c670f1e7127fc20ff2371cb0b.tar.gz
hugo-e4d6ec94b5c1ea1c670f1e7127fc20ff2371cb0b.zip
Allow user to handle/ignore errors in resources.Get
In Hugo 0.90.0 we introduced remote support in `resources.Get`. But with remote resources comes with a higher chance of failing a build (network issues, remote server down etc.). Before this commit we always failed the build on any unexpected error. This commit allows the user to check for any error (and potentially fall back to a default local resource): ```htmlbars {{ $result := resources.Get "https://gohugo.io/img/hugo-logo.png" }} {{ with $result }} {{ if .Err }} {{/* log the error, insert a default image etc. *}} {{ else }} <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt=""> {{ end }} {{ end }} ``` Note that the default behaviour is still to fail the build, but we will delay that error until you start using the `Resource`. Fixes #9529
Diffstat (limited to 'resources/resource')
-rw-r--r--resources/resource/resourcetypes.go1
1 files changed, 1 insertions, 0 deletions
diff --git a/resources/resource/resourcetypes.go b/resources/resource/resourcetypes.go
index 8ab77e436..788cdb86a 100644
--- a/resources/resource/resourcetypes.go
+++ b/resources/resource/resourcetypes.go
@@ -45,6 +45,7 @@ type Resource interface {
ResourceMetaProvider
ResourceParamsProvider
ResourceDataProvider
+ Err() error
}
// Image represents an image resource.