package warpc_test
import (
+ "path/filepath"
+ "runtime"
"testing"
qt "github.com/frankban/quicktest"
{{ $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.
"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"
// 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)
}
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) {