summaryrefslogtreecommitdiffstats
path: root/resource
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-03 14:58:09 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-16 22:10:56 +0200
commit35fbfb19a173b01bc881f2bbc5d104136633a7ec (patch)
tree636d0d51fa262dc808eb3c5cc9cf92ad977a0c6a /resource
parent3a3089121b852332b5744d1f566959c8cf93cef4 (diff)
commands: Show server error info in browser
The main item in this commit is showing of errors with a file context when running `hugo server`. This can be turned off: `hugo server --disableBrowserError` (can also be set in `config.toml`). But to get there, the error handling in Hugo needed a revision. There are some items left TODO for commits soon to follow, most notable errors in content and config files. Fixes #5284 Fixes #5290 See #5325 See #5324
Diffstat (limited to 'resource')
-rw-r--r--resource/image.go6
-rw-r--r--resource/postcss/postcss.go11
-rw-r--r--resource/resource.go12
-rw-r--r--resource/resource_metadata.go3
-rw-r--r--resource/templates/execute_as_template.go5
-rw-r--r--resource/tocss/scss/tocss.go3
-rw-r--r--resource/tocss/scss/tocss_notavailable.go4
-rw-r--r--resource/transform.go4
8 files changed, 24 insertions, 24 deletions
diff --git a/resource/image.go b/resource/image.go
index e8b87cdb4..d9a1dd47d 100644
--- a/resource/image.go
+++ b/resource/image.go
@@ -26,6 +26,8 @@ import (
"strings"
"sync"
+ _errors "github.com/pkg/errors"
+
"github.com/disintegration/imaging"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/helpers"
@@ -430,7 +432,7 @@ func (i *Image) initConfig() error {
})
if err != nil {
- return fmt.Errorf("failed to load image config: %s", err)
+ return _errors.Wrap(err, "failed to load image config")
}
return nil
@@ -439,7 +441,7 @@ func (i *Image) initConfig() error {
func (i *Image) decodeSource() (image.Image, error) {
f, err := i.ReadSeekCloser()
if err != nil {
- return nil, fmt.Errorf("failed to open image for decode: %s", err)
+ return nil, _errors.Wrap(err, "failed to open image for decode")
}
defer f.Close()
img, _, err := image.Decode(f)
diff --git a/resource/postcss/postcss.go b/resource/postcss/postcss.go
index 202b4c06b..ec73543dd 100644
--- a/resource/postcss/postcss.go
+++ b/resource/postcss/postcss.go
@@ -14,19 +14,18 @@
package postcss
import (
- "fmt"
"io"
"path/filepath"
"github.com/gohugoio/hugo/hugofs"
+ "github.com/pkg/errors"
- "github.com/mitchellh/mapstructure"
- // "io/ioutil"
"os"
"os/exec"
- "github.com/gohugoio/hugo/common/errors"
+ "github.com/mitchellh/mapstructure"
+ "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/resource"
)
@@ -111,7 +110,7 @@ func (t *postcssTransformation) Transform(ctx *resource.ResourceTransformationCt
binary = binaryName
if _, err := exec.LookPath(binary); err != nil {
// This may be on a CI server etc. Will fall back to pre-built assets.
- return errors.ErrFeatureNotAvailable
+ return herrors.ErrFeatureNotAvailable
}
}
@@ -134,7 +133,7 @@ func (t *postcssTransformation) Transform(ctx *resource.ResourceTransformationCt
if err != nil {
if t.options.Config != "" {
// Only fail if the user specificed config file is not found.
- return fmt.Errorf("postcss config %q not found: %s", configFile, err)
+ return errors.Wrapf(err, "postcss config %q not found:", configFile)
}
configFile = ""
} else {
diff --git a/resource/resource.go b/resource/resource.go
index dd9cbbd41..be3ebdb8b 100644
--- a/resource/resource.go
+++ b/resource/resource.go
@@ -14,7 +14,6 @@
package resource
import (
- "errors"
"fmt"
"io"
"io/ioutil"
@@ -27,13 +26,12 @@ import (
"github.com/gohugoio/hugo/output"
"github.com/gohugoio/hugo/tpl"
+ "github.com/pkg/errors"
"github.com/gohugoio/hugo/common/collections"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/common/loggers"
- jww "github.com/spf13/jwalterweatherman"
-
"github.com/spf13/afero"
"github.com/gobwas/glob"
@@ -273,7 +271,7 @@ type Spec struct {
MediaTypes media.Types
OutputFormats output.Formats
- Logger *jww.Notepad
+ Logger *loggers.Logger
TextTemplates tpl.TemplateParseFinder
@@ -287,7 +285,7 @@ type Spec struct {
GenAssetsPath string
}
-func NewSpec(s *helpers.PathSpec, logger *jww.Notepad, outputFormats output.Formats, mimeTypes media.Types) (*Spec, error) {
+func NewSpec(s *helpers.PathSpec, logger *loggers.Logger, outputFormats output.Formats, mimeTypes media.Types) (*Spec, error) {
imaging, err := decodeImaging(s.Cfg.GetStringMap("imaging"))
if err != nil {
@@ -542,7 +540,7 @@ type resourceHash struct {
type publishOnce struct {
publisherInit sync.Once
publisherErr error
- logger *jww.Notepad
+ logger *loggers.Logger
}
func (l *publishOnce) publish(s Source) error {
@@ -660,7 +658,7 @@ func (l *genericResource) initHash() error {
var f hugio.ReadSeekCloser
f, err = l.ReadSeekCloser()
if err != nil {
- err = fmt.Errorf("failed to open source file: %s", err)
+ err = errors.Wrap(err, "failed to open source file")
return
}
defer f.Close()
diff --git a/resource/resource_metadata.go b/resource/resource_metadata.go
index 2c82aeaf6..20c4f130b 100644
--- a/resource/resource_metadata.go
+++ b/resource/resource_metadata.go
@@ -17,6 +17,7 @@ import (
"fmt"
"strconv"
+ "github.com/pkg/errors"
"github.com/spf13/cast"
"strings"
@@ -69,7 +70,7 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...Resource) er
glob, err := getGlob(srcKey)
if err != nil {
- return fmt.Errorf("failed to match resource with metadata: %s", err)
+ return errors.Wrap(err, "failed to match resource with metadata")
}
match := glob.Match(resourceSrcKey)
diff --git a/resource/templates/execute_as_template.go b/resource/templates/execute_as_template.go
index dee9d0d9a..a126b26c9 100644
--- a/resource/templates/execute_as_template.go
+++ b/resource/templates/execute_as_template.go
@@ -15,11 +15,10 @@
package templates
import (
- "fmt"
-
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resource"
"github.com/gohugoio/hugo/tpl"
+ "github.com/pkg/errors"
)
// Client contains methods to perform template processing of Resource objects.
@@ -55,7 +54,7 @@ func (t *executeAsTemplateTransform) Transform(ctx *resource.ResourceTransformat
tplStr := helpers.ReaderToString(ctx.From)
templ, err := t.textTemplate.Parse(ctx.InPath, tplStr)
if err != nil {
- return fmt.Errorf("failed to parse Resource %q as Template: %s", ctx.InPath, err)
+ return errors.Wrapf(err, "failed to parse Resource %q as Template:", ctx.InPath)
}
ctx.OutPath = t.targetPath
diff --git a/resource/tocss/scss/tocss.go b/resource/tocss/scss/tocss.go
index 5ba7793c0..984e14fc2 100644
--- a/resource/tocss/scss/tocss.go
+++ b/resource/tocss/scss/tocss.go
@@ -29,6 +29,7 @@ import (
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/resource"
+ "github.com/pkg/errors"
)
// Used in tests. This feature requires Hugo to be built with the extended tag.
@@ -165,7 +166,7 @@ func (c *Client) toCSS(options scss.Options, dst io.Writer, src io.Reader) (tocs
res, err = transpiler.Execute(dst, src)
if err != nil {
- return res, fmt.Errorf("SCSS processing failed: %s", err)
+ return res, errors.Wrap(err, "SCSS processing failed")
}
return res, nil
diff --git a/resource/tocss/scss/tocss_notavailable.go b/resource/tocss/scss/tocss_notavailable.go
index 2ec5a4832..df918b368 100644
--- a/resource/tocss/scss/tocss_notavailable.go
+++ b/resource/tocss/scss/tocss_notavailable.go
@@ -16,7 +16,7 @@
package scss
import (
- "github.com/gohugoio/hugo/common/errors"
+ "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/resource"
)
@@ -26,5 +26,5 @@ func Supports() bool {
}
func (t *toCSSTransformation) Transform(ctx *resource.ResourceTransformationCtx) error {
- return errors.ErrFeatureNotAvailable
+ return herrors.ErrFeatureNotAvailable
}
diff --git a/resource/transform.go b/resource/transform.go
index 01b05b73e..d3a215467 100644
--- a/resource/transform.go
+++ b/resource/transform.go
@@ -20,7 +20,7 @@ import (
"strings"
"github.com/gohugoio/hugo/common/collections"
- "github.com/gohugoio/hugo/common/errors"
+ "github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hugio"
"github.com/gohugoio/hugo/helpers"
"github.com/mitchellh/hashstructure"
@@ -390,7 +390,7 @@ func (r *transformedResource) transform(setContent bool) (err error) {
}
if err := tr.transformation.Transform(tctx); err != nil {
- if err == errors.ErrFeatureNotAvailable {
+ if err == herrors.ErrFeatureNotAvailable {
// This transformation is not available in this
// Hugo installation (scss not compiled in, PostCSS not available etc.)
// If a prepared bundle for this transformation chain is available, use that.