The relevant error that I’m seeing when I try to build my website with Hugo:
execute of template failed: template: _shortcodes/feed-updated.html:3:12: executing “_shortcodes/feed-updated.html” at <.Err>: can’t evaluate field Err in type resource.Resource: Resource.Err was removed in Hugo v0.141.0 and replaced with a new try keyword, see try
I’ve reviewed the documentation, as well as the only forum thread I’ve found that seems to address this issue (“Unexpected breakage in 0.141.0“), and I’m still confused about what changes I need to make in the shortcode that I’ve been using:
{{ with .Get "url" }}
{{ with resources.GetRemote . }}
{{ with .Err }}
{{ warnf "%s" . }}
{{ else }}
{{ with .Content | transform.Unmarshal }}
{{ with .channel.item }}
{{ range first 1 . }}
{{ with .pubDate }}
{{ dateFormat "2006-01-02" . }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
Thank you for responding so quickly. Unfortunately, the Hugo build failed:
execute of template failed: template: _shortcodes/feed-updated.html:6:14: executing "_shortcodes/feed-updated.html" at <.Content>: can't evaluate field Content in type template.TryValue
Your shortcode, with some additional error checking:
{{ with $url := .Get "url" }}
{{ with try (resources.GetRemote .) }}
{{ with .Err }}
{{ errorf "The %q shortcode was unable to get the remote resource %s: %s: see %s" $.Name $url . $.Position }}
{{ else with .Value }}
{{ with . | transform.Unmarshal }}
{{ with .channel.item }}
{{ range first 1 . }}
{{ with .pubDate }}
{{ dateFormat "2006-01-02" . }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode was unable to get the remote resource %s: see %s" $.Name $url $.Position }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode requires a argument named url: see %s" .Name .Position }}
{{ end }}
I also have an etiquette question: Should I go back to original thread and add a note to look in this thread for updated code? I would hate for someone to view the thread from last year, try the code, and have to figure out why it doesn’t work for them.
What is the failing URL?
Which hugo version?
Which OS?
Can you try this locally?
git clone --single-branch -b hugo-forum-topic-55568 https://github.com/jmooring/hugo-testing hugo-forum-topic-55568
cd hugo-forum-topic-55568
hugo server
Or share your repository?
In the meantime, switch back to passing .Content to transform.Unmarshal.
And to figure which URLs are causing the problem, you can wrap the transform.Unmarshal bit in another try statement, e.g.
{{ with $url := .Get "url" }}
{{ with try (resources.GetRemote .) }}
{{ with .Err }}
{{ errorf "The %q shortcode was unable to get the remote resource %s: %s: see %s" $.Name $url . $.Position }}
{{ else with .Value }}
{{ with try (. | transform.Unmarshal) }}
{{ with .Err }}
{{ errorf "The %q shortcode was unable to unmarshal the remote resource %s: %s: see %s" $.Name $url . $.Position }}
{{ else with .Value }}
{{ with .channel.item }}
{{ range first 1 . }}
{{ with .pubDate }}
{{ dateFormat "2006-01-02" . }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode was unable to get the remote resource %s: see %s" $.Name $url $.Position }}
{{ end }}
{{ end }}
{{ else }}
{{ errorf "The %q shortcode requires a argument named url: see %s" .Name .Position }}
{{ end }}
Or don’t worry about it and, as I suggested earlier, go back to passing .Content to transform.Unmarshal and don’t worry about the performance hit.
I used this latest code, and also deleted the two lines that refer to RSS and it works well. Thank you!
After poking around in my code, my memory, my bookmarks, and my notes to myself, I think the RSS references are legacy code. I switched to Atom and left them in the file in case the code that I used to change to Atom didn’t work properly and I needed to roll back my updates (this was before I was using Git to manage my website).
I remain deeply impressed with your dedication to Hugo and its users. I can’t imagine publishing my writing with a different platform. Again, apologies for not being able to update the previous thread. I hope that anyone who’s using this code finds this thread and makes the necessary updates.