aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-07-17 19:15:48 +0200
committerBjørn Erik Pedersen <[email protected]>2023-07-17 20:42:32 +0200
commit387c5f60f97141d638327f84ee426fb44f6c554e (patch)
treedd9b40c4f33532183d2e84b8ea09e7dc72cb1b4a /resources
parentc406fd3a0e0efa17f69095ca6317ba1036fc8964 (diff)
downloadhugo-387c5f60f97141d638327f84ee426fb44f6c554e.tar.gz
hugo-387c5f60f97141d638327f84ee426fb44f6c554e.zip
Improve error messages for PostCSS etc.
Fixes #9730
Diffstat (limited to 'resources')
-rw-r--r--resources/resource_transformers/babel/babel.go4
-rw-r--r--resources/resource_transformers/postcss/integration_test.go19
-rw-r--r--resources/resource_transformers/postcss/postcss.go6
-rw-r--r--resources/transform.go2
4 files changed, 26 insertions, 5 deletions
diff --git a/resources/resource_transformers/babel/babel.go b/resources/resource_transformers/babel/babel.go
index 5f8fcb00f..2999d73cb 100644
--- a/resources/resource_transformers/babel/babel.go
+++ b/resources/resource_transformers/babel/babel.go
@@ -181,7 +181,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
if err != nil {
if hexec.IsNotFound(err) {
// This may be on a CI server etc. Will fall back to pre-built assets.
- return herrors.ErrFeatureNotAvailable
+ return &herrors.FeatureNotAvailableError{Cause: err}
}
return err
}
@@ -200,7 +200,7 @@ func (t *babelTransformation) Transform(ctx *resources.ResourceTransformationCtx
err = cmd.Run()
if err != nil {
if hexec.IsNotFound(err) {
- return herrors.ErrFeatureNotAvailable
+ return &herrors.FeatureNotAvailableError{Cause: err}
}
return fmt.Errorf(errBuf.String()+": %w", err)
}
diff --git a/resources/resource_transformers/postcss/integration_test.go b/resources/resource_transformers/postcss/integration_test.go
index c920fe17d..74aaa2661 100644
--- a/resources/resource_transformers/postcss/integration_test.go
+++ b/resources/resource_transformers/postcss/integration_test.go
@@ -168,6 +168,25 @@ func TestTransformPostCSSError(t *testing.T) {
}
+func TestTransformPostCSSNotInstalledError(t *testing.T) {
+ if !htesting.IsCI() {
+ t.Skip("Skip long running test when running locally")
+ }
+
+ c := qt.New(t)
+
+ s, err := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: c,
+ NeedsOsFS: true,
+ TxtarString: postCSSIntegrationTestFiles,
+ }).BuildE()
+
+ s.AssertIsFileError(err)
+ c.Assert(err.Error(), qt.Contains, `binary with name "npx" not found`)
+
+}
+
// #9895
func TestTransformPostCSSImportError(t *testing.T) {
if !htesting.IsCI() {
diff --git a/resources/resource_transformers/postcss/postcss.go b/resources/resource_transformers/postcss/postcss.go
index 083607246..a65fa3783 100644
--- a/resources/resource_transformers/postcss/postcss.go
+++ b/resources/resource_transformers/postcss/postcss.go
@@ -205,7 +205,7 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
if err != nil {
if hexec.IsNotFound(err) {
// This may be on a CI server etc. Will fall back to pre-built assets.
- return herrors.ErrFeatureNotAvailable
+ return &herrors.FeatureNotAvailableError{Cause: err}
}
return err
}
@@ -240,7 +240,9 @@ func (t *postcssTransformation) Transform(ctx *resources.ResourceTransformationC
err = cmd.Run()
if err != nil {
if hexec.IsNotFound(err) {
- return herrors.ErrFeatureNotAvailable
+ return &herrors.FeatureNotAvailableError{
+ Cause: err,
+ }
}
return imp.toFileError(errBuf.String())
}
diff --git a/resources/transform.go b/resources/transform.go
index 9e5b57625..eb7d8fb0b 100644
--- a/resources/transform.go
+++ b/resources/transform.go
@@ -449,7 +449,7 @@ func (r *resourceAdapter) transform(publish, setContent bool) error {
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 {
+ if herrors.IsFeatureNotAvailableError(err) {
var errMsg string
if tr.Key().Name == "postcss" {
// This transformation is not available in this