Updating from Err to TryValue?

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.

1 Like