mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +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:
@@ -22,13 +22,14 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"errors"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
|
||||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/common/text"
|
||||
|
||||
"github.com/gohugoio/hugo/hugolib/filesystems"
|
||||
"github.com/gohugoio/hugo/media"
|
||||
@@ -109,13 +110,13 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
for i, ext := range opts.Inject {
|
||||
impPath := filepath.FromSlash(ext)
|
||||
if filepath.IsAbs(impPath) {
|
||||
return errors.Errorf("inject: absolute paths not supported, must be relative to /assets")
|
||||
return fmt.Errorf("inject: absolute paths not supported, must be relative to /assets")
|
||||
}
|
||||
|
||||
m := resolveComponentInAssets(t.c.rs.Assets.Fs, impPath)
|
||||
|
||||
if m == nil {
|
||||
return errors.Errorf("inject: file %q not found", ext)
|
||||
return fmt.Errorf("inject: file %q not found", ext)
|
||||
}
|
||||
|
||||
opts.Inject[i] = m.Filename
|
||||
@@ -157,10 +158,12 @@ func (t *buildTransformation) Transform(ctx *resources.ResourceTransformationCtx
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
fe := herrors.NewFileError("js", 0, loc.Line, loc.Column, errors.New(msg.Text))
|
||||
err, _ := herrors.WithFileContext(fe, path, f, herrors.SimpleLineMatcher)
|
||||
fe := herrors.NewFileError(path, errors.New(msg.Text)).
|
||||
UpdatePosition(text.Position{Offset: -1, LineNumber: loc.Line, ColumnNumber: loc.Column}).
|
||||
UpdateContent(f, herrors.SimpleLineMatcher)
|
||||
|
||||
f.Close()
|
||||
return err
|
||||
return fe
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s", msg.Text)
|
||||
|
Reference in New Issue
Block a user