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 /commands/hugo.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 'commands/hugo.go')
-rw-r--r-- | commands/hugo.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index 9033fac90..6bd0605db 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -39,9 +39,6 @@ import ( "github.com/gohugoio/hugo/resources/page" - "github.com/pkg/errors" - - "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/hugo" "github.com/gohugoio/hugo/common/loggers" "github.com/gohugoio/hugo/common/terminal" @@ -300,14 +297,14 @@ func (c *commandeer) fullBuild(noBuildLock bool) error { copyStaticFunc := func() error { cnt, err := c.copyStatic() if err != nil { - return errors.Wrap(err, "Error copying static files") + return fmt.Errorf("Error copying static files: %w", err) } langCount = cnt return nil } buildSitesFunc := func() error { if err := c.buildSites(noBuildLock); err != nil { - return errors.Wrap(err, "Error building site") + return fmt.Errorf("Error building site: %w", err) } return nil } @@ -354,10 +351,10 @@ func (c *commandeer) initCPUProfile() (func(), error) { f, err := os.Create(c.h.cpuprofile) if err != nil { - return nil, errors.Wrap(err, "failed to create CPU profile") + return nil, fmt.Errorf("failed to create CPU profile: %w", err) } if err := pprof.StartCPUProfile(f); err != nil { - return nil, errors.Wrap(err, "failed to start CPU profile") + return nil, fmt.Errorf("failed to start CPU profile: %w", err) } return func() { pprof.StopCPUProfile() @@ -388,11 +385,11 @@ func (c *commandeer) initTraceProfile() (func(), error) { f, err := os.Create(c.h.traceprofile) if err != nil { - return nil, errors.Wrap(err, "failed to create trace file") + return nil, fmt.Errorf("failed to create trace file: %w", err) } if err := trace.Start(f); err != nil { - return nil, errors.Wrap(err, "failed to start trace") + return nil, fmt.Errorf("failed to start trace: %w", err) } return func() { @@ -735,9 +732,7 @@ func (c *commandeer) handleBuildErr(err error, msg string) { c.logger.Errorln(msg + ":\n") c.logger.Errorln(helpers.FirstUpper(err.Error())) - if !c.h.quiet && c.h.verbose { - herrors.PrintStackTraceFromErr(err) - } + } func (c *commandeer) rebuildSites(events []fsnotify.Event) error { |