aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/transform.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-03-10 18:12:11 +0100
committerBjørn Erik Pedersen <[email protected]>2020-03-11 14:13:03 +0100
commitdf298558a5a5b747288d9656402af85e0ac75a43 (patch)
treeed62ce971aeead7cf1833a8e9310dd69cbaa565f /resources/transform.go
parentb1106f8715cac3544b8ea662b969336fe56fa047 (diff)
downloadhugo-df298558a5a5b747288d9656402af85e0ac75a43.tar.gz
hugo-df298558a5a5b747288d9656402af85e0ac75a43.zip
Improve Tailwind/PostCSS error messages
Fixes #7041 Fixes #7042
Diffstat (limited to 'resources/transform.go')
-rw-r--r--resources/transform.go41
1 files changed, 29 insertions, 12 deletions
diff --git a/resources/transform.go b/resources/transform.go
index 8d8eb0303..e88307afe 100644
--- a/resources/transform.go
+++ b/resources/transform.go
@@ -28,6 +28,7 @@ import (
bp "github.com/gohugoio/hugo/bufferpool"
+ "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/helpers"
@@ -392,16 +393,24 @@ func (r *resourceAdapter) transform(publish, setContent bool) error {
}
}
- notAvailableErr := func(err error) error {
- errMsg := err.Error()
- if tr.Key().Name == "postcss" {
- // This transformation is not available in this
- // Most likely because PostCSS is not installed.
- errMsg += ". Check your PostCSS installation; install with \"npm install postcss-cli\". See https://gohugo.io/hugo-pipes/postcss/"
- } else if tr.Key().Name == "tocss" {
- errMsg += ". Check your Hugo installation; you need the extended version to build SCSS/SASS."
+ newErr := func(err error) error {
+
+ msg := fmt.Sprintf("%s: failed to transform %q (%s)", strings.ToUpper(tr.Key().Name), tctx.InPath, tctx.InMediaType.Type())
+
+ if err == herrors.ErrFeatureNotAvailable {
+ var errMsg string
+ if tr.Key().Name == "postcss" {
+ // This transformation is not available in this
+ // Most likely because PostCSS is not installed.
+ errMsg = ". Check your PostCSS installation; install with \"npm install postcss-cli\". See https://gohugo.io/hugo-pipes/postcss/"
+ } else if tr.Key().Name == "tocss" {
+ errMsg = ". Check your Hugo installation; you need the extended version to build SCSS/SASS."
+ }
+
+ return errors.New(msg + errMsg)
}
- return fmt.Errorf("%s: failed to transform %q (%s): %s", strings.ToUpper(tr.Key().Name), tctx.InPath, tctx.InMediaType.Type(), errMsg)
+
+ return errors.Wrap(err, msg)
}
@@ -411,18 +420,22 @@ func (r *resourceAdapter) transform(publish, setContent bool) error {
tryFileCache = true
} else {
err = tr.Transform(tctx)
+ if err != nil && err != herrors.ErrFeatureNotAvailable {
+ return newErr(err)
+ }
+
if mayBeCachedOnDisk {
tryFileCache = r.spec.BuildConfig.UseResourceCache(err)
}
if err != nil && !tryFileCache {
- return notAvailableErr(err)
+ return newErr(err)
}
}
if tryFileCache {
f := r.target.tryTransformedFileCache(key, updates)
if f == nil {
- return notAvailableErr(errors.Errorf("resource %q not found in file cache", key))
+ return newErr(errors.Errorf("resource %q not found in file cache", key))
}
transformedContentr = f
updates.sourceFs = cache.fileCache.Fs
@@ -525,7 +538,11 @@ func (r *resourceAdapter) initTransform(publish, setContent bool) {
r.transformationsErr = r.transform(publish, setContent)
if r.transformationsErr != nil {
- r.spec.Logger.ERROR.Printf("Transformation failed: %s", r.transformationsErr)
+ if r.spec.ErrorSender != nil {
+ r.spec.ErrorSender.SendError(r.transformationsErr)
+ } else {
+ r.spec.Logger.ERROR.Printf("Transformation failed: %s", r.transformationsErr)
+ }
}
})