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
This commit is contained in:
Bjørn Erik Pedersen
2022-05-02 16:07:52 +02:00
parent 6eea32bd6b
commit f2946da9e8
109 changed files with 861 additions and 780 deletions

13
deps/deps.go vendored
View File

@@ -1,12 +1,11 @@
package deps
import (
"fmt"
"sync"
"sync/atomic"
"time"
"github.com/pkg/errors"
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
@@ -186,11 +185,11 @@ func (d *Deps) SetTextTmpl(tmpl tpl.TemplateParseFinder) {
func (d *Deps) LoadResources() error {
// Note that the translations need to be loaded before the templates.
if err := d.translationProvider.Update(d); err != nil {
return errors.Wrap(err, "loading translations")
return fmt.Errorf("loading translations: %w", err)
}
if err := d.templateProvider.Update(d); err != nil {
return errors.Wrap(err, "loading templates")
return fmt.Errorf("loading templates: %w", err)
}
return nil
@@ -236,18 +235,18 @@ func New(cfg DepsCfg) (*Deps, error) {
securityConfig, err := security.DecodeConfig(cfg.Cfg)
if err != nil {
return nil, errors.WithMessage(err, "failed to create security config from configuration")
return nil, fmt.Errorf("failed to create security config from configuration: %w", err)
}
execHelper := hexec.New(securityConfig)
ps, err := helpers.NewPathSpec(fs, cfg.Language, logger)
if err != nil {
return nil, errors.Wrap(err, "create PathSpec")
return nil, fmt.Errorf("create PathSpec: %w", err)
}
fileCaches, err := filecache.NewCaches(ps)
if err != nil {
return nil, errors.WithMessage(err, "failed to create file caches from configuration")
return nil, fmt.Errorf("failed to create file caches from configuration: %w", err)
}
errorHandler := &globalErrHandler{}