]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Add full filename to image processing error messages if possible
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 18 Dec 2025 10:32:42 +0000 (11:32 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 18 Dec 2025 16:46:26 +0000 (17:46 +0100)
Fixes #14278

internal/warpc/webp_integration_test.go
resources/image.go
resources/resource.go

index 5e45e2491bca880e1c3d4f647a049de321ef6637..8a98541b2fa74553e27082a33f3fd117cd76eac0 100644 (file)
@@ -14,6 +14,8 @@
 package warpc_test
 
 import (
+       "path/filepath"
+       "runtime"
        "testing"
 
        qt "github.com/frankban/quicktest"
@@ -70,10 +72,19 @@ sourcefilename: ../../resources/testdata/webp/invalid.webp
 {{ $resized := $image.Resize "123x456 webp" }}
 Resized RelPermalink: {{ $resized.RelPermalink }}|
 `
+       tempDir := t.TempDir()
 
-       b, err := hugolib.TestE(t, files)
-
+       b, err := hugolib.TestE(t, files, hugolib.TestOptWithConfig(func(cfg *hugolib.IntegrationTestConfig) {
+               cfg.NeedsOsFS = true
+               cfg.WorkingDir = tempDir
+       }))
        b.Assert(err, qt.IsNotNil)
+
+       if runtime.GOOS != "windows" {
+               // Make sure the full image filename is in the error message.
+               filename := filepath.Join(tempDir, "assets/invalid.webp")
+               b.Assert(err.Error(), qt.Contains, filename)
+       }
 }
 
 // This test isn't great, but we have golden tests to verify the output itself.
index d487cd69befb4340917b4067e7a3b674d0d3c000..694d0f75239cac04a3aaf837c2099ebceb40431f 100644 (file)
@@ -28,7 +28,6 @@ import (
 
        "github.com/gohugoio/hugo/cache/filecache"
        "github.com/gohugoio/hugo/common/hashing"
-       "github.com/gohugoio/hugo/common/herrors"
        "github.com/gohugoio/hugo/common/paths"
 
        "github.com/disintegration/gift"
@@ -212,7 +211,6 @@ func (i *imageResource) Process(spec string) (images.ImageResource, error) {
 // filter and returns the transformed image. If one of width or height is 0, the image aspect
 // ratio is preserved.
 func (i *imageResource) Resize(spec string) (images.ImageResource, error) {
-       defer herrors.Recover()
        return i.processActionSpec(images.ActionResize, spec)
 }
 
@@ -291,7 +289,14 @@ func (i *imageResource) Filter(filters ...any) (images.ImageResource, error) {
 
 func (i *imageResource) processActionSpec(action, spec string) (images.ImageResource, error) {
        options := append([]string{action}, strings.Fields(strings.ToLower(spec))...)
-       return i.processOptions(options)
+       ir, err := i.processOptions(options)
+       if err != nil {
+               if sourcePath := i.sourcePath(); sourcePath != "" {
+                       err = fmt.Errorf("failed to %s image %q: %w", action, sourcePath, err)
+               }
+               return nil, err
+       }
+       return ir, nil
 }
 
 func (i *imageResource) processOptions(options []string) (images.ImageResource, error) {
index 9886f2db4c0c8c9bdf8dcf52fe596297a702b039..1666e76921c2cb5fc1e5303e7e9f32ebcdf1502c 100644 (file)
@@ -242,6 +242,7 @@ type baseResourceInternal interface {
        resource.Source
        resource.NameNormalizedProvider
 
+       sourcePath() string
        fileInfo
        mediaTypeAssigner
        targetPather