]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
resources: Replace error handling in GetRemote with try (note)
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 5 Jan 2025 14:43:18 +0000 (15:43 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 6 Jan 2025 11:22:17 +0000 (12:22 +0100)
Closes #13216

16 files changed:
common/herrors/file_error.go
hugolib/hugo_sites_build.go
hugolib/page.go
hugolib/resource_chain_test.go
resources/errorResource.go [deleted file]
resources/page/page_nop.go
resources/page/testhelpers_test.go
resources/resource.go
resources/resource/resourcetypes.go
resources/resource_factories/create/create_integration_test.go
resources/transform.go
tpl/internal/go_templates/texttemplate/hugo_template.go
tpl/resources/resources.go
tpl/tplimpl/embedded/templates/shortcodes/twitter.html
tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html

index c8a48823e82f2b41429339175c40b89443e14340..38b1986568bbfb347534c7d024378664df68d0b0 100644 (file)
@@ -258,8 +258,27 @@ func openFile(filename string, fs afero.Fs) (afero.File, string, error) {
        return f, realFilename, nil
 }
 
-// Cause returns the underlying error or itself if it does not implement Unwrap.
+// Cause returns the underlying error, that is,
+// it unwraps errors until it finds one that does not implement
+// the Unwrap method.
+// For a shallow variant, see Unwrap.
 func Cause(err error) error {
+       type unwrapper interface {
+               Unwrap() error
+       }
+
+       for err != nil {
+               cause, ok := err.(unwrapper)
+               if !ok {
+                       break
+               }
+               err = cause.Unwrap()
+       }
+       return err
+}
+
+// Unwrap returns the underlying error or itself if it does not implement Unwrap.
+func Unwrap(err error) error {
        if u := errors.Unwrap(err); u != nil {
                return u
        }
@@ -267,7 +286,7 @@ func Cause(err error) error {
 }
 
 func extractFileTypePos(err error) (string, text.Position) {
-       err = Cause(err)
+       err = Unwrap(err)
 
        var fileType string
 
index 02ecd57855d772e224295d245069cbd8ab2e295f..60fb8ecc02f9c610de839a8a2917c5203d853e06 100644 (file)
@@ -343,6 +343,18 @@ func (h *HugoSites) render(l logg.LevelLogger, config *BuildCfg) error {
 
        siteRenderContext := &siteRenderContext{cfg: config, multihost: h.Configs.IsMultihost}
 
+       renderErr := func(err error) error {
+               if err == nil {
+                       return nil
+               }
+               if strings.Contains(err.Error(), "can't evaluate field Err in type resource.Resource") {
+                       // In Hugo 0.141.0 we replaced the special error handling for resources.GetRemote
+                       // with the more general try.
+                       return fmt.Errorf("%s: Resource.Err was removed in Hugo v0.141.0 and replaced with a new try keyword, see https://gohugo.io/functions/go-template/try/", err)
+               }
+               return err
+       }
+
        i := 0
        for _, s := range h.Sites {
                segmentFilter := s.conf.C.SegmentFilter
@@ -390,7 +402,7 @@ func (h *HugoSites) render(l logg.LevelLogger, config *BuildCfg) error {
                                                        }
                                                } else {
                                                        if err := s.render(siteRenderContext); err != nil {
-                                                               return err
+                                                               return renderErr(err)
                                                        }
                                                }
                                                loggers.TimeTrackf(ll, start, nil, "")
index 83f0c6e25c2a7393fcf5089b2d46f2d3d3f1b81a..3653767379a4b826ae8f107e667405be96568671 100644 (file)
@@ -185,10 +185,6 @@ func (p *pageState) isContentNodeBranch() bool {
        return p.IsNode()
 }
 
-func (p *pageState) Err() resource.ResourceError {
-       return nil
-}
-
 // Eq returns whether the current page equals the given page.
 // This is what's invoked when doing `{{ if eq $page $otherPage }}`
 func (p *pageState) Eq(other any) bool {
index 0b17a8db09114950ab6e9febd47ec3bea93b1c28..669114c8a4acd48604d89821e6444eb5bbfc1c54 100644 (file)
@@ -67,11 +67,11 @@ FIT: {{ $fit.Name }}|{{ $fit.RelPermalink }}|{{ $fit.Width }}
 CSS integrity Data first: {{ $cssFingerprinted1.Data.Integrity }} {{ $cssFingerprinted1.RelPermalink }}
 CSS integrity Data last:  {{ $cssFingerprinted2.RelPermalink }} {{ $cssFingerprinted2.Data.Integrity }}
 
-{{ $failedImg := resources.GetRemote "%[1]s/fail.jpg" }}
+{{ $failedImg := try (resources.GetRemote "%[1]s/fail.jpg") }}
 {{ $rimg := resources.GetRemote "%[1]s/sunset.jpg" }}
 {{ $remotenotfound := resources.GetRemote "%[1]s/notfound.jpg" }}
 {{ $localnotfound := resources.Get "images/notfound.jpg" }}
-{{ $gopherprotocol := resources.GetRemote "gopher://example.org" }}
+{{ $gopherprotocol := try (resources.GetRemote "gopher://example.org") }}
 {{ $rfit := $rimg.Fit "200x200" }}
 {{ $rfit2 := $rfit.Fit "100x200" }}
 {{ $rimg = $rimg | fingerprint }}
@@ -79,10 +79,10 @@ SUNSET REMOTE: {{ $rimg.Name }}|{{ $rimg.RelPermalink }}|{{ $rimg.Width }}|{{ le
 FIT REMOTE: {{ $rfit.Name }}|{{ $rfit.RelPermalink }}|{{ $rfit.Width }}
 REMOTE NOT FOUND: {{ if $remotenotfound }}FAILED{{ else}}OK{{ end }}
 LOCAL NOT FOUND: {{ if $localnotfound }}FAILED{{ else}}OK{{ end }}
-PRINT PROTOCOL ERROR1: {{ with $gopherprotocol }}{{ . | safeHTML }}{{ end }}
+PRINT PROTOCOL ERROR1: {{ with $gopherprotocol }}{{ .Value | safeHTML }}{{ end }}
 PRINT PROTOCOL ERROR2: {{ with $gopherprotocol }}{{ .Err | safeHTML }}{{ end }}
-PRINT PROTOCOL ERROR DETAILS: {{ with $gopherprotocol }}Err: {{ .Err | safeHTML }}{{ with .Err }}|{{ with .Data }}Body: {{ .Body }}|StatusCode: {{ .StatusCode }}{{ end }}|{{ end }}{{ end }}
-FAILED REMOTE ERROR DETAILS CONTENT: {{ with $failedImg.Err }}|{{ . }}|{{ with .Data }}Body: {{ .Body }}|StatusCode: {{ .StatusCode }}|ContentLength: {{ .ContentLength }}|ContentType: {{ .ContentType }}{{ end }}{{ end }}|
+PRINT PROTOCOL ERROR DETAILS: {{ with $gopherprotocol }}{{ with .Err }}Err: {{ . | safeHTML }}{{ with .Cause }}|{{ with .Data }}Body: {{ .Body }}|StatusCode: {{ .StatusCode }}{{ end }}|{{ end }}{{ end }}{{ end }}
+FAILED REMOTE ERROR DETAILS CONTENT: {{ with $failedImg }}{{ with .Err }}{{ with .Cause }}{{ . }}|{{ with .Data }}Body: {{ .Body }}|StatusCode: {{ .StatusCode }}|ContentLength: {{ .ContentLength }}|ContentType: {{ .ContentType }}{{ end }}{{ end }}{{ end }}{{ end }}|
 `, ts.URL))
 
        fs := b.Fs.Source
@@ -114,8 +114,8 @@ SUNSET REMOTE: /sunset_%[1]s.jpg|/sunset_%[1]s.a9bf1d944e19c0f382e0d8f51de690f7d
 FIT REMOTE: /sunset_%[1]s.jpg|/sunset_%[1]s_hu15210517121918042184.jpg|200
 REMOTE NOT FOUND: OK
 LOCAL NOT FOUND: OK
-PRINT PROTOCOL ERROR DETAILS: Err: error calling resources.GetRemote: Get "gopher://example.org": unsupported protocol scheme "gopher"||
-FAILED REMOTE ERROR DETAILS CONTENT: |failed to fetch remote resource from &#39;%[2]s/fail.jpg&#39;: Not Implemented|Body: { msg: failed }
+PRINT PROTOCOL ERROR DETAILS: Err: template: index.html:22:36: executing "index.html" at <resources.GetRemote>: error calling GetRemote: Get "gopher://example.org": unsupported protocol scheme "gopher"|
+FAILED REMOTE ERROR DETAILS CONTENT: failed to fetch remote resource from &#39;%[2]s/fail.jpg&#39;: Not Implemented|Body: { msg: failed }
 |StatusCode: 501|ContentLength: 16|ContentType: text/plain; charset=utf-8|
 
 
diff --git a/resources/errorResource.go b/resources/errorResource.go
deleted file mode 100644 (file)
index 582c54f..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2021 The Hugo Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package resources
-
-import (
-       "context"
-       "image"
-
-       "github.com/gohugoio/hugo/common/hugio"
-       "github.com/gohugoio/hugo/common/maps"
-       "github.com/gohugoio/hugo/media"
-       "github.com/gohugoio/hugo/resources/images"
-       "github.com/gohugoio/hugo/resources/images/exif"
-       "github.com/gohugoio/hugo/resources/resource"
-)
-
-var (
-       _ error = (*errorResource)(nil)
-       // Image covers all current Resource implementations.
-       _ images.ImageResource = (*errorResource)(nil)
-       // The list of user facing and exported interfaces in resource.go
-       // Note that if we're missing some interface here, the user will still
-       // get an error, but not as pretty.
-       _ resource.ContentResource         = (*errorResource)(nil)
-       _ resource.ReadSeekCloserResource  = (*errorResource)(nil)
-       _ resource.ResourcesLanguageMerger = (*resource.Resources)(nil)
-       // Make sure it also fails when passed to a pipe function.
-       _ ResourceTransformer = (*errorResource)(nil)
-)
-
-// NewErrorResource wraps err in a Resource where all but the Err method will panic.
-func NewErrorResource(err resource.ResourceError) resource.Resource {
-       return &errorResource{ResourceError: err}
-}
-
-type errorResource struct {
-       resource.ResourceError
-}
-
-func (e *errorResource) Err() resource.ResourceError {
-       return e.ResourceError
-}
-
-func (e *errorResource) ReadSeekCloser() (hugio.ReadSeekCloser, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Content(context.Context) (any, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) ResourceType() string {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) MediaType() media.Type {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Permalink() string {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) RelPermalink() string {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Name() string {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Title() string {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Params() maps.Params {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Data() any {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Height() int {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Width() int {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Process(spec string) (images.ImageResource, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Crop(spec string) (images.ImageResource, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Fill(spec string) (images.ImageResource, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Fit(spec string) (images.ImageResource, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Resize(spec string) (images.ImageResource, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Filter(filters ...any) (images.ImageResource, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Exif() *exif.ExifInfo {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Colors() ([]images.Color, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) DecodeImage() (image.Image, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) Transform(...ResourceTransformation) (ResourceTransformer, error) {
-       panic(e.ResourceError)
-}
-
-func (e *errorResource) TransformWithContext(context.Context, ...ResourceTransformation) (ResourceTransformer, error) {
-       panic(e.ResourceError)
-}
index 5a03b19941cb49580555558c842a908e8c55e3e0..af9f2682d37db019ad9a41344288b35190da8880 100644 (file)
@@ -61,10 +61,6 @@ type nopPage int
 
 var noOpPathInfo = media.DefaultPathParser.Parse(files.ComponentFolderContent, "no-op.md")
 
-func (p *nopPage) Err() resource.ResourceError {
-       return nil
-}
-
 func (p *nopPage) Aliases() []string {
        return nil
 }
index 8a2d28e31fe53eb3eaea40601b760016e442f29f..8e6dfb79ac2ff57586c8dc7259e9cfb21aaa0632 100644 (file)
@@ -111,10 +111,6 @@ type testPage struct {
        sectionEntries []string
 }
 
-func (p *testPage) Err() resource.ResourceError {
-       return nil
-}
-
 func (p *testPage) Aliases() []string {
        panic("testpage: not implemented")
 }
index 7ab10b0ae34db7413f22b8f6ced0c9dc1fd7cc45..29b9e5ddd8211cb84793fc2bec95b58d40d84ff7 100644 (file)
@@ -224,9 +224,6 @@ type resourceCopier interface {
 
 // Copy copies r to the targetPath given.
 func Copy(r resource.Resource, targetPath string) resource.Resource {
-       if r.Err() != nil {
-               panic(fmt.Sprintf("Resource has an .Err: %s", r.Err()))
-       }
        return r.(resourceCopier).cloneTo(targetPath)
 }
 
@@ -439,10 +436,6 @@ func (l *genericResource) Content(context.Context) (any, error) {
        return hugio.ReadString(r)
 }
 
-func (r *genericResource) Err() resource.ResourceError {
-       return nil
-}
-
 func (l *genericResource) Data() any {
        return l.sd.Data
 }
index b33750e8033b294a508fb4718e7970585c6a2180..585dfd1505ef9cb341dfba0cdab18e30e7fcdc1e 100644 (file)
@@ -43,6 +43,9 @@ type OriginProvider interface {
 
 // NewResourceError creates a new ResourceError.
 func NewResourceError(err error, data any) ResourceError {
+       if data == nil {
+               data = map[string]any{}
+       }
        return &resourceError{
                error: err,
                data:  data,
@@ -65,13 +68,6 @@ type ResourceError interface {
        ResourceDataProvider
 }
 
-// ErrProvider provides an Err.
-type ErrProvider interface {
-       // Err returns an error if this resource is in an error state.
-       // This will currently only be set for resources obtained from resources.GetRemote.
-       Err() ResourceError
-}
-
 // Resource represents a linkable resource, i.e. a content page, image etc.
 type Resource interface {
        ResourceWithoutMeta
@@ -83,7 +79,6 @@ type ResourceWithoutMeta interface {
        MediaTypeProvider
        ResourceLinksProvider
        ResourceDataProvider
-       ErrProvider
 }
 
 type ResourceWrapper interface {
index 17084574da9e356a8ab754783346624bd140ac0a..7b9c96e34974b0ec78b2d888208aaf4a4d0abbcc 100644 (file)
@@ -31,18 +31,17 @@ func TestGetRemoteHead(t *testing.T) {
   [security.http]
     methods = ['(?i)GET|POST|HEAD']
     urls = ['.*gohugo\.io.*']
-
 -- layouts/index.html --
 {{ $url := "https://gohugo.io/img/hugo.png" }}
 {{ $opts := dict "method" "head" }}
-{{ with resources.GetRemote $url $opts }}
+{{ with try (resources.GetRemote $url $opts) }}
   {{ with .Err }}
     {{ errorf "Unable to get remote resource: %s" . }}
-  {{ else }}
+  {{ else with .Value }}
     Head Content: {{ .Content }}. Head Data: {{ .Data }}
-  {{ end }}
-{{ else }}
+  {{ else }}
   {{ errorf "Unable to get remote resource: %s" $url }}
+  {{ end }}
 {{ end }}
 `
 
@@ -90,14 +89,15 @@ mediaTypes = ['text/plain']
 -- layouts/_default/single.html --
 {{ $url := printf "%s%s" "URL" .RelPermalink}}
 {{ $opts := dict }}
-{{ with resources.GetRemote $url $opts }}
+{{ with try (resources.GetRemote $url $opts) }}
   {{ with .Err }}
-    {{ errorf "Got Err: %s. Data: %v" . .Data }}
-  {{ else }}
+     {{ errorf "Got Err: %s" . }}
+        {{ with .Cause }}{{ errorf "Data: %s" .Data }}{{ end }}
+  {{ else with .Value }}
     Content: {{ .Content }}
+  {{ else }}
+    {{ errorf "Unable to get remote resource: %s" $url }}
   {{ end }}
-{{ else }}
-  {{ errorf "Unable to get remote resource: %s" $url }}
 {{ end }}
 `
 
index c5d24066937fd01e891ae294c937f6fb3ead78cc..73f3b85d25dfd50d20f74241ccf38971546e1a8b 100644 (file)
@@ -192,10 +192,6 @@ func (r *resourceAdapter) Content(ctx context.Context) (any, error) {
        return r.target.Content(ctx)
 }
 
-func (r *resourceAdapter) Err() resource.ResourceError {
-       return nil
-}
-
 func (r *resourceAdapter) GetIdentity() identity.Identity {
        return identity.FirstIdentity(r.target)
 }
index 0dbee02f73384c44c69f18324bc7d9aced38b71e..36962c444b8f85f972eba909dd87b59b770dabbf 100644 (file)
@@ -19,6 +19,7 @@ import (
        "io"
        "reflect"
 
+       "github.com/gohugoio/hugo/common/herrors"
        "github.com/gohugoio/hugo/common/hreflect"
 
        "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
@@ -256,14 +257,34 @@ func (s *state) evalField(dot reflect.Value, fieldName string, node parse.Node,
        panic("not reached")
 }
 
+// newErrorWithCause creates a new error with the given cause.
+func newErrorWithCause(err error) *TryError {
+       return &TryError{Err: err, Cause: herrors.Cause(err)}
+}
+
+// TryError wraps an error with a cause.
+type TryError struct {
+       Err   error
+       Cause error
+}
+
+func (e *TryError) Error() string {
+       return e.Err.Error()
+}
+
+func (e *TryError) Unwrap() error {
+       return e.Err
+}
+
 // TryValue is what gets returned when using the "try" keyword.
 type TryValue struct {
        // Value is the value returned by the function or method wrapped with "try".
        // This will always be nil if Err is set.
        Value any
+
        // Err is the error returned by the function or method wrapped with "try".
        // This will always be nil if Value is set.
-       Err error
+       Err *TryError
 }
 
 // evalCall executes a function or method call. If it's a method, fun already has the receiver bound, so
@@ -274,10 +295,11 @@ func (s *state) evalCall(dot, fun reflect.Value, isBuiltin bool, node parse.Node
        if name == "try" {
                defer func() {
                        if r := recover(); r != nil {
+                               // Cause: herrors.Cause(err)
                                if err, ok := r.(error); ok {
-                                       val = reflect.ValueOf(TryValue{nil, err})
+                                       val = reflect.ValueOf(TryValue{Value: nil, Err: newErrorWithCause(err)})
                                } else {
-                                       val = reflect.ValueOf(TryValue{nil, fmt.Errorf("%v", r)})
+                                       val = reflect.ValueOf(TryValue{Value: nil, Err: newErrorWithCause(fmt.Errorf("%v", r))})
                                }
                        }
                }()
@@ -396,7 +418,7 @@ func (s *state) evalCall(dot, fun reflect.Value, isBuiltin bool, node parse.Node
 
        // Added for Hugo.
        if name == "try" {
-               return reflect.ValueOf(TryValue{vv.Interface(), nil})
+               return reflect.ValueOf(TryValue{Value: vv.Interface()})
        }
 
        return vv
index beace14e6c82d6493f4913cdecad566db3a417a7..f28cc36fe07cab59829195f512574cebd57a5017 100644 (file)
@@ -115,14 +115,10 @@ func (ns *Namespace) Get(filename any) resource.Resource {
 //
 // Note: This method does not return any error as a second return value,
 // for any error situations the error can be checked in .Err.
-func (ns *Namespace) GetRemote(args ...any) resource.Resource {
+func (ns *Namespace) GetRemote(args ...any) (resource.Resource, error) {
        get := func(args ...any) (resource.Resource, error) {
-               if len(args) < 1 {
-                       return nil, errors.New("must provide an URL")
-               }
-
-               if len(args) > 2 {
-                       return nil, errors.New("must not provide more arguments than URL and options")
+               if len(args) < 1 || len(args) > 2 {
+                       return nil, errors.New("must provide an URL and optionally an options map")
                }
 
                urlstr, err := cast.ToStringE(args[0])
@@ -146,12 +142,12 @@ func (ns *Namespace) GetRemote(args ...any) resource.Resource {
        if err != nil {
                switch v := err.(type) {
                case *create.HTTPError:
-                       return resources.NewErrorResource(resource.NewResourceError(v, v.Data))
+                       return nil, resource.NewResourceError(v, v.Data)
                default:
-                       return resources.NewErrorResource(resource.NewResourceError(fmt.Errorf("error calling resources.GetRemote: %w", err), make(map[string]any)))
+                       return nil, resource.NewResourceError(err, nil)
                }
        }
-       return r
+       return r, nil
 }
 
 // GetMatch finds the first Resource matching the given pattern, or nil if none found.
index ba5a851eeb33df0410ad4965613dd26af9f2c48e..b88cf7ce0ea7122a102194803d94a3af2682e25f 100644 (file)
   {{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
   {{- $query := querify "url" $url "dnt" .dnt -}}
   {{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
-  {{- with resources.GetRemote $request -}}
+  {{- with try (resources.GetRemote $request) -}}
     {{- with .Err -}}
       {{- errorf "%s" . -}}
-    {{- else -}}
+    {{- else with .Value -}}
       {{- (. | transform.Unmarshal).html | safeHTML -}}
-    {{- end -}}
-  {{- else -}}
+    {{- else -}}
     {{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
+    {{- end -}}
   {{- end -}}
 {{- end -}}
index 1f3b3c523ea5f19aef3796407ce2def15deac382..0fc8613b9387c7a813e4b4e63ee3c600f11e1dd1 100644 (file)
   {{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
   {{- $query := querify "url" $url "dnt" .dnt "omit_script" true -}}
   {{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
-  {{- with resources.GetRemote $request -}}
+  {{- with try (resources.GetRemote $request) -}}
     {{- with .Err -}}
       {{- errorf "%s" . -}}
-    {{- else -}}
+    {{- else with .Value -}}
       {{- (. | transform.Unmarshal).html | safeHTML -}}
+    {{- else -}}
+      {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
     {{- end -}}
-  {{- else -}}
-    {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
   {{- end -}}
 {{- end -}}
 
     {{- .Page.Scratch.Set "__h_simple_twitter_css" true -}}
     <style type="text/css">
       .twitter-tweet {
-        font: 14px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
+        font:
+          14px/1.45 -apple-system,
+          BlinkMacSystemFont,
+          "Segoe UI",
+          Roboto,
+          Oxygen-Sans,
+          Ubuntu,
+          Cantarell,
+          "Helvetica Neue",
+          sans-serif;
         border-left: 4px solid #2b7bb9;
         padding-left: 1.5em;
         color: #555;
index e262d3c3cb05c22d3b14599268ea24441fb8d45c..7f7940b804d9199d9a1c1e3687cd57b3b052126f 100644 (file)
   {{- $url := urls.JoinPath "https://vimeo.com" .id -}}
   {{- $query := querify "url" $url "dnt" $dnt -}}
   {{- $request := printf "https://vimeo.com/api/oembed.json?%s" $query -}}
-  {{- with resources.GetRemote $request -}}
+  {{- with try (resources.GetRemote $request) -}}
     {{- with .Err -}}
       {{- errorf "%s" . -}}
-    {{- else -}}
+    {{- else with .Value -}}
       {{- with . | transform.Unmarshal -}}
         {{- $class := printf "%s %s" "s_video_simple" "__h_video" -}}
         {{- with $.class -}}
@@ -45,8 +45,8 @@
           </a>
         </div>
       {{- end -}}
+    {{- else -}}
+      {{- warnidf "shortcode-vimeo-simple" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
     {{- end -}}
-  {{- else -}}
-    {{- warnidf "shortcode-vimeo-simple" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
   {{- end -}}
 {{- end -}}