From f2946da9e806c2bafbdd26707fe339db79bd980b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 2 May 2022 16:07:52 +0200 Subject: 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 --- deps/deps.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'deps') diff --git a/deps/deps.go b/deps/deps.go index a9e78860d..ece420302 100644 --- a/deps/deps.go +++ b/deps/deps.go @@ -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{} -- cgit v1.2.3