]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
resources: Improve getImageOps error message
authorJoe Mooring <joe.mooring@veriphor.com>
Thu, 26 Feb 2026 19:08:08 +0000 (11:08 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 26 Feb 2026 21:20:08 +0000 (22:20 +0100)
Closes #14571

resources/resources_integration_test.go
resources/transform.go

index 1cc870f807c0a9d1ca5e47050ae68256311d765e..8d0f13bb6be45f594f1edb1ce8c8573c917ea190 100644 (file)
@@ -97,7 +97,7 @@ Width: {{ $svg.Width }}
                }).BuildE()
 
        b.Assert(err, qt.IsNotNil)
-       b.Assert(err.Error(), qt.Contains, `error calling Width: this method is only available for raster images. To determine if an image is SVG, you can do {{ if eq .MediaType.SubType "svg" }}{{ end }}`)
+       b.Assert(err.Error(), qt.Contains, `error calling Width: resource "/circle.svg" of media type "image/svg+xml" does not support this method: use reflect.IsImageResource, reflect.IsImageResourceProcessable, or reflect.IsImageResourceWithMeta to check if the resource supports this method before calling it`)
 }
 
 // Issue 10255.
index bcacf5471e3e5067c9b8660cfe06b9c20b9595c5..169c50895e902adab952cecfeef4d8db230760d0 100644 (file)
@@ -395,12 +395,20 @@ func (r resourceAdapter) WithResourceMeta(mp resource.ResourceMetaProvider) reso
 func (r *resourceAdapter) getImageOps() images.ImageResourceOps {
        img, ok := r.target.(images.ImageResourceOps)
        if !ok {
-               if r.MediaType().SubType == "svg" {
-                       panic("this method is only available for raster images. To determine if an image is SVG, you can do {{ if eq .MediaType.SubType \"svg\" }}{{ end }}")
-               }
-               panic("this method is only available for image resources")
+               instructions := "use reflect.IsImageResource, " +
+                       "reflect.IsImageResourceProcessable, or " +
+                       "reflect.IsImageResourceWithMeta to check if the resource " +
+                       "supports this method before calling it"
+               msg := fmt.Sprintf(
+                       "resource %q of media type %q does not support this method: %s",
+                       r.Name(),
+                       r.MediaType(),
+                       instructions,
+               )
+               panic(msg)
        }
        r.init(false, false)
+
        return img
 }