0.90.0 how to check for local resource existence?

With 0.89 I used to be able to do something like:

{{ with resources.Get $image }}
{{ $image = (.Fit "200x200").RelPermalink }}
{{ end }}

This way, if $image pointed to a local resource, it would get transformed the way I like. But if $image pointed to, say, a picture somewhere on the interwebs, it would be passed further verbatim.

0.90.0 breaks this behaviour: even if $image is an external picture, it will get fetched and transformed. Even worse: if the external resource is unavailable (offline, in another network, etc) at the time of the build, the build fails with an error.

Is there a way to work around this regression while maintaining the original logic in the code snippet?

There 1) We do have some retries on remote errors … 2) Also, once fetched it will be cached on disk.

You can do something like this:

{{ if not (urls.Parse $image).Scheme }}
{{ with resources.Get $image }}
{{ $image = (.Fit "200x200").RelPermalink }}
{{ end }}
{{ end }}
1 Like

Too bad there isn’t an option to check if there was an error and handle it gracefully in a template, rather than make the whole build fail because of something you have no control over in the first place…

Yea, we may need to add some better error handling. Thanks for the constructive feedback!

3 Likes
3 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.