mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
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:
@@ -36,7 +36,7 @@ import (
|
||||
|
||||
"github.com/rogpeppe/go-internal/module"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/spf13/afero"
|
||||
@@ -48,7 +48,7 @@ const vendorModulesFilename = "modules.txt"
|
||||
|
||||
// IsNotExist returns whether an error means that a module could not be found.
|
||||
func IsNotExist(err error) bool {
|
||||
return errors.Cause(err) == ErrNotExist
|
||||
return errors.Is(err, os.ErrNotExist)
|
||||
}
|
||||
|
||||
// CreateProjectModule creates modules from the given config.
|
||||
@@ -289,7 +289,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||
return nil, nil
|
||||
}
|
||||
if found, _ := afero.Exists(c.fs, moduleDir); !found {
|
||||
c.err = c.wrapModuleNotFound(errors.Errorf(`module %q not found; either add it as a Hugo Module or store it in %q.`, modulePath, c.ccfg.ThemesDir))
|
||||
c.err = c.wrapModuleNotFound(fmt.Errorf(`module %q not found; either add it as a Hugo Module or store it in %q.`, modulePath, c.ccfg.ThemesDir))
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
@@ -297,7 +297,7 @@ func (c *collector) add(owner *moduleAdapter, moduleImport Import, disabled bool
|
||||
}
|
||||
|
||||
if found, _ := afero.Exists(c.fs, moduleDir); !found {
|
||||
c.err = c.wrapModuleNotFound(errors.Errorf("%q not found", moduleDir))
|
||||
c.err = c.wrapModuleNotFound(fmt.Errorf("%q not found", moduleDir))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ func (c *collector) collectModulesTXT(owner Module) error {
|
||||
line = strings.TrimSpace(line)
|
||||
parts := strings.Fields(line)
|
||||
if len(parts) != 2 {
|
||||
return errors.Errorf("invalid modules list: %q", filename)
|
||||
return fmt.Errorf("invalid modules list: %q", filename)
|
||||
}
|
||||
path := parts[0]
|
||||
|
||||
@@ -662,7 +662,7 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
|
||||
targetBase = mnt.Target[0:idxPathSep]
|
||||
}
|
||||
if !files.IsComponentFolder(targetBase) {
|
||||
return nil, errors.Errorf("%s: mount target must be one of: %v", errMsg, files.ComponentFolders)
|
||||
return nil, fmt.Errorf("%s: mount target must be one of: %v", errMsg, files.ComponentFolders)
|
||||
}
|
||||
|
||||
out = append(out, mnt)
|
||||
@@ -672,7 +672,7 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
|
||||
}
|
||||
|
||||
func (c *collector) wrapModuleNotFound(err error) error {
|
||||
err = errors.Wrap(ErrNotExist, err.Error())
|
||||
err = fmt.Errorf(err.Error()+": %w", ErrNotExist)
|
||||
if c.GoModulesFilename == "" {
|
||||
return err
|
||||
}
|
||||
@@ -681,9 +681,9 @@ func (c *collector) wrapModuleNotFound(err error) error {
|
||||
|
||||
switch c.goBinaryStatus {
|
||||
case goBinaryStatusNotFound:
|
||||
return errors.Wrap(err, baseMsg+" you need to install Go to use it. See https://golang.org/dl/.")
|
||||
return fmt.Errorf(baseMsg+" you need to install Go to use it. See https://golang.org/dl/ : %q", err)
|
||||
case goBinaryStatusTooOld:
|
||||
return errors.Wrap(err, baseMsg+" you need to a newer version of Go to use it. See https://golang.org/dl/.")
|
||||
return fmt.Errorf(baseMsg+" you need to a newer version of Go to use it. See https://golang.org/dl/ : %w", err)
|
||||
}
|
||||
|
||||
return err
|
||||
|
Reference in New Issue
Block a user