diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-02 16:07:52 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-05-06 19:43:22 +0200 |
commit | f2946da9e806c2bafbdd26707fe339db79bd980b (patch) | |
tree | b5609317a861ea5f399e094e1b9287ca71dc22d1 /create/content.go | |
parent | 6eea32bd6bc8e7a7dd07a8cb6a8343ae2c74aba0 (diff) |
Improve error messages, esp. when the server is running
* Add file context to minifier errors when publishing
* Misc fixes (see issues)
* Allow custom server error template in layouts/server/error.html
To get to this, this commit also cleans up and simplifies the code surrounding errors and files. This also removes the usage of `github.com/pkg/errors`, mostly because of https://github.com/pkg/errors/issues/223 -- but also because most of this is now built-in to Go.
Fixes #9852
Fixes #9857
Fixes #9863
Diffstat (limited to 'create/content.go')
-rw-r--r-- | create/content.go | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/create/content.go b/create/content.go index 9034ba299..5f05e25f9 100644 --- a/create/content.go +++ b/create/content.go @@ -27,7 +27,7 @@ import ( "github.com/gohugoio/hugo/common/hexec" "github.com/gohugoio/hugo/common/paths" - "github.com/pkg/errors" + "errors" "github.com/gohugoio/hugo/hugofs/files" @@ -94,11 +94,11 @@ func NewContent(h *hugolib.HugoSites, kind, targetPath string) error { } if ext == "" { - return "", errors.Errorf("failed to resolve %q to a archetype template", targetPath) + return "", fmt.Errorf("failed to resolve %q to a archetype template", targetPath) } if !files.IsContentFile(b.targetPath) { - return "", errors.Errorf("target path %q is not a known content format", b.targetPath) + return "", fmt.Errorf("target path %q is not a known content format", b.targetPath) } return b.buildFile() @@ -188,14 +188,14 @@ func (b *contentBuilder) buildDir() error { in, err := meta.Open() if err != nil { - return errors.Wrap(err, "failed to open non-content file") + return fmt.Errorf("failed to open non-content file: %w", err) } targetFilename := filepath.Join(baseDir, b.targetPath, strings.TrimPrefix(filename, b.archetypeFilename)) targetDir := filepath.Dir(targetFilename) if err := b.sourceFs.MkdirAll(targetDir, 0o777); err != nil && !os.IsExist(err) { - return errors.Wrapf(err, "failed to create target directory for %q", targetDir) + return fmt.Errorf("failed to create target directory for %q: %w", targetDir, err) } out, err := b.sourceFs.Create(targetFilename) @@ -329,7 +329,7 @@ func (b *contentBuilder) mapArcheTypeDir() error { w := hugofs.NewWalkway(walkCfg) if err := w.Walk(); err != nil { - return errors.Wrapf(err, "failed to walk archetype dir %q", b.archetypeFilename) + return fmt.Errorf("failed to walk archetype dir %q: %w", b.archetypeFilename, err) } b.dirMap = m @@ -374,7 +374,7 @@ func (b *contentBuilder) usesSiteVar(filename string) (bool, error) { } bb, err := afero.ReadFile(b.archeTypeFs, filename) if err != nil { - return false, errors.Wrap(err, "failed to open archetype file") + return false, fmt.Errorf("failed to open archetype file: %w", err) } return bytes.Contains(bb, []byte(".Site")) || bytes.Contains(bb, []byte("site.")), nil |