summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-02 16:07:52 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-06 19:43:22 +0200
commitf2946da9e806c2bafbdd26707fe339db79bd980b (patch)
treeb5609317a861ea5f399e094e1b9287ca71dc22d1 /tpl
parent6eea32bd6bc8e7a7dd07a8cb6a8343ae2c74aba0 (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 'tpl')
-rw-r--r--tpl/collections/collections.go5
-rw-r--r--tpl/collections/merge.go9
-rw-r--r--tpl/collections/reflect_helpers.go5
-rw-r--r--tpl/collections/symdiff.go4
-rw-r--r--tpl/data/data.go8
-rw-r--r--tpl/data/resources.go5
-rw-r--r--tpl/images/images.go2
-rw-r--r--tpl/internal/resourcehelpers/helpers.go4
-rw-r--r--tpl/lang/lang.go5
-rw-r--r--tpl/openapi/openapi3/openapi3.go5
-rw-r--r--tpl/resources/resources.go7
-rw-r--r--tpl/strings/strings.go14
-rw-r--r--tpl/tplimpl/embedded/templates/server/error.html63
-rw-r--r--tpl/tplimpl/template.go15
-rw-r--r--tpl/tplimpl/template_ast_transformers.go10
-rw-r--r--tpl/tplimpl/template_errors.go20
-rw-r--r--tpl/transform/remarshal.go2
-rw-r--r--tpl/transform/unmarshal.go12
-rw-r--r--tpl/urls/urls.go3
19 files changed, 131 insertions, 67 deletions
diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go
index 24f43e62c..516e2c272 100644
--- a/tpl/collections/collections.go
+++ b/tpl/collections/collections.go
@@ -24,12 +24,13 @@ import (
"strings"
"time"
+ "errors"
+
"github.com/gohugoio/hugo/common/collections"
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/common/types"
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
- "github.com/pkg/errors"
"github.com/spf13/cast"
)
@@ -736,7 +737,7 @@ func (ns *Namespace) Uniq(seq any) (any, error) {
case reflect.Array:
slice = reflect.MakeSlice(reflect.SliceOf(v.Type().Elem()), 0, 0)
default:
- return nil, errors.Errorf("type %T not supported", seq)
+ return nil, fmt.Errorf("type %T not supported", seq)
}
seen := make(map[any]bool)
diff --git a/tpl/collections/merge.go b/tpl/collections/merge.go
index abfc2da9c..4d408302b 100644
--- a/tpl/collections/merge.go
+++ b/tpl/collections/merge.go
@@ -14,13 +14,14 @@
package collections
import (
+ "fmt"
"reflect"
"strings"
"github.com/gohugoio/hugo/common/hreflect"
"github.com/gohugoio/hugo/common/maps"
- "github.com/pkg/errors"
+ "errors"
)
// Merge creates a copy of the final parameter and merges the preceding
@@ -49,7 +50,7 @@ func (ns *Namespace) merge(src, dst any) (any, error) {
vdst, vsrc := reflect.ValueOf(dst), reflect.ValueOf(src)
if vdst.Kind() != reflect.Map {
- return nil, errors.Errorf("destination must be a map, got %T", dst)
+ return nil, fmt.Errorf("destination must be a map, got %T", dst)
}
if !hreflect.IsTruthfulValue(vsrc) {
@@ -57,11 +58,11 @@ func (ns *Namespace) merge(src, dst any) (any, error) {
}
if vsrc.Kind() != reflect.Map {
- return nil, errors.Errorf("source must be a map, got %T", src)
+ return nil, fmt.Errorf("source must be a map, got %T", src)
}
if vsrc.Type().Key() != vdst.Type().Key() {
- return nil, errors.Errorf("incompatible map types, got %T to %T", src, dst)
+ return nil, fmt.Errorf("incompatible map types, got %T to %T", src, dst)
}
return mergeMap(vdst, vsrc).Interface(), nil
diff --git a/tpl/collections/reflect_helpers.go b/tpl/collections/reflect_helpers.go
index 4aa137e88..4178850aa 100644
--- a/tpl/collections/reflect_helpers.go
+++ b/tpl/collections/reflect_helpers.go
@@ -18,8 +18,9 @@ import (
"reflect"
"time"
+ "errors"
+
"github.com/mitchellh/hashstructure"
- "github.com/pkg/errors"
)
var (
@@ -103,7 +104,7 @@ func convertValue(v reflect.Value, to reflect.Type) (reflect.Value, error) {
case isNumber(kind):
return convertNumber(v, kind)
default:
- return reflect.Value{}, errors.Errorf("%s is not assignable to %s", v.Type(), to)
+ return reflect.Value{}, fmt.Errorf("%s is not assignable to %s", v.Type(), to)
}
}
diff --git a/tpl/collections/symdiff.go b/tpl/collections/symdiff.go
index 1c411bc35..8ecee3c4a 100644
--- a/tpl/collections/symdiff.go
+++ b/tpl/collections/symdiff.go
@@ -16,8 +16,6 @@ package collections
import (
"fmt"
"reflect"
-
- "github.com/pkg/errors"
)
// SymDiff returns the symmetric difference of s1 and s2.
@@ -54,7 +52,7 @@ func (ns *Namespace) SymDiff(s2, s1 any) (any, error) {
if ids1[key] != ids2[key] {
v, err := convertValue(ev, sliceElemType)
if err != nil {
- return nil, errors.WithMessage(err, "symdiff: failed to convert value")
+ return nil, fmt.Errorf("symdiff: failed to convert value: %w", err)
}
slice = reflect.Append(slice, v)
}
diff --git a/tpl/data/data.go b/tpl/data/data.go
index 5e03d52c3..926f6773d 100644
--- a/tpl/data/data.go
+++ b/tpl/data/data.go
@@ -20,6 +20,7 @@ import (
"encoding/csv"
"encoding/json"
"errors"
+ "fmt"
"net/http"
"strings"
@@ -35,7 +36,6 @@ import (
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/deps"
- _errors "github.com/pkg/errors"
)
// New returns a new instance of the data-namespaced template functions.
@@ -69,7 +69,7 @@ func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) {
unmarshal := func(b []byte) (bool, error) {
if d, err = parseCSV(b, sep); err != nil {
- err = _errors.Wrapf(err, "failed to parse CSV file %s", url)
+ err = fmt.Errorf("failed to parse CSV file %s: %w", url, err)
return true, err
}
@@ -80,7 +80,7 @@ func (ns *Namespace) GetCSV(sep string, args ...any) (d [][]string, err error) {
var req *http.Request
req, err = http.NewRequest("GET", url, nil)
if err != nil {
- return nil, _errors.Wrapf(err, "failed to create request for getCSV for resource %s", url)
+ return nil, fmt.Errorf("failed to create request for getCSV for resource %s: %w", url, err)
}
// Add custom user headers.
@@ -109,7 +109,7 @@ func (ns *Namespace) GetJSON(args ...any) (any, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
- return nil, _errors.Wrapf(err, "Failed to create request for getJSON resource %s", url)
+ return nil, fmt.Errorf("Failed to create request for getJSON resource %s: %w", url, err)
}
unmarshal := func(b []byte) (bool, error) {
diff --git a/tpl/data/resources.go b/tpl/data/resources.go
index dca25efb2..0470faf51 100644
--- a/tpl/data/resources.go
+++ b/tpl/data/resources.go
@@ -15,14 +15,13 @@ package data
import (
"bytes"
+ "fmt"
"io/ioutil"
"net/http"
"net/url"
"path/filepath"
"time"
- "github.com/pkg/errors"
-
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/config"
@@ -70,7 +69,7 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b
res.Body.Close()
if isHTTPError(res) {
- return nil, errors.Errorf("Failed to retrieve remote file: %s, body: %q", http.StatusText(res.StatusCode), b)
+ return nil, fmt.Errorf("Failed to retrieve remote file: %s, body: %q", http.StatusText(res.StatusCode), b)
}
retry, err = unmarshal(b)
diff --git a/tpl/images/images.go b/tpl/images/images.go
index 20af019cf..1abee1b0c 100644
--- a/tpl/images/images.go
+++ b/tpl/images/images.go
@@ -18,7 +18,7 @@ import (
"image"
"sync"
- "github.com/pkg/errors"
+ "errors"
"github.com/gohugoio/hugo/resources/images"
diff --git a/tpl/internal/resourcehelpers/helpers.go b/tpl/internal/resourcehelpers/helpers.go
index d1c9bbb75..2d50c59a4 100644
--- a/tpl/internal/resourcehelpers/helpers.go
+++ b/tpl/internal/resourcehelpers/helpers.go
@@ -19,8 +19,6 @@ import (
"errors"
"fmt"
- _errors "github.com/pkg/errors"
-
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/resources"
)
@@ -64,7 +62,7 @@ func ResolveArgs(args []any) (resources.ResourceTransformer, map[string]any, err
m, err := maps.ToStringMapE(args[0])
if err != nil {
- return nil, nil, _errors.Wrap(err, "invalid options type")
+ return nil, nil, fmt.Errorf("invalid options type: %w", err)
}
return r, m, nil
diff --git a/tpl/lang/lang.go b/tpl/lang/lang.go
index ee349bd1d..17d37faa4 100644
--- a/tpl/lang/lang.go
+++ b/tpl/lang/lang.go
@@ -20,9 +20,10 @@ import (
"strconv"
"strings"
+ "errors"
+
"github.com/gohugoio/locales"
translators "github.com/gohugoio/localescompressed"
- "github.com/pkg/errors"
"github.com/gohugoio/hugo/common/hreflect"
"github.com/gohugoio/hugo/deps"
@@ -49,7 +50,7 @@ func (ns *Namespace) Translate(id any, args ...any) (string, error) {
if len(args) > 0 {
if len(args) > 1 {
- return "", errors.Errorf("wrong number of arguments, expecting at most 2, got %d", len(args)+1)
+ return "", fmt.Errorf("wrong number of arguments, expecting at most 2, got %d", len(args)+1)
}
templateData = args[0]
}
diff --git a/tpl/openapi/openapi3/openapi3.go b/tpl/openapi/openapi3/openapi3.go
index 276673889..1eea04b25 100644
--- a/tpl/openapi/openapi3/openapi3.go
+++ b/tpl/openapi/openapi3/openapi3.go
@@ -14,11 +14,12 @@
package openapi3
import (
+ "fmt"
"io/ioutil"
gyaml "github.com/ghodss/yaml"
- "github.com/pkg/errors"
+ "errors"
kopenapi3 "github.com/getkin/kin-openapi/openapi3"
"github.com/gohugoio/hugo/cache/namedmemcache"
@@ -57,7 +58,7 @@ func (ns *Namespace) Unmarshal(r resource.UnmarshableResource) (*kopenapi3.T, er
v, err := ns.cache.GetOrCreate(key, func() (any, error) {
f := metadecoders.FormatFromMediaType(r.MediaType())
if f == "" {
- return nil, errors.Errorf("MIME %q not supported", r.MediaType())
+ return nil, fmt.Errorf("MIME %q not supported", r.MediaType())
}
reader, err := r.ReadSeekCloser()
diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go
index d3a98002f..2adec358c 100644
--- a/tpl/resources/resources.go
+++ b/tpl/resources/resources.go
@@ -20,8 +20,9 @@ import (
"github.com/gohugoio/hugo/common/herrors"
+ "errors"
+
"github.com/gohugoio/hugo/common/maps"
- "github.com/pkg/errors"
"github.com/gohugoio/hugo/tpl/internal/resourcehelpers"
@@ -162,7 +163,7 @@ func (ns *Namespace) GetRemote(args ...any) resource.Resource {
case *create.HTTPError:
return resources.NewErrorResource(resource.NewResourceError(v, v.Data))
default:
- return resources.NewErrorResource(resource.NewResourceError(errors.Wrap(err, "error calling resources.GetRemote"), make(map[string]any)))
+ return resources.NewErrorResource(resource.NewResourceError(fmt.Errorf("error calling resources.GetRemote: %w", err), make(map[string]any)))
}
}
@@ -354,7 +355,7 @@ func (ns *Namespace) ToCSS(args ...any) (resource.Resource, error) {
case transpilerDart, transpilerLibSass:
transpiler = cast.ToString(t)
default:
- return nil, errors.Errorf("unsupported transpiler %q; valid values are %q or %q", t, transpilerLibSass, transpilerDart)
+ return nil, fmt.Errorf("unsupported transpiler %q; valid values are %q or %q", t, transpilerLibSass, transpilerDart)
}
}
}
diff --git a/tpl/strings/strings.go b/tpl/strings/strings.go
index 000490f85..482a8a837 100644
--- a/tpl/strings/strings.go
+++ b/tpl/strings/strings.go
@@ -16,6 +16,7 @@ package strings
import (
"errors"
+ "fmt"
"html/template"
"regexp"
"strings"
@@ -25,7 +26,6 @@ import (
"github.com/gohugoio/hugo/deps"
"github.com/gohugoio/hugo/helpers"
- _errors "github.com/pkg/errors"
"github.com/spf13/cast"
)
@@ -48,7 +48,7 @@ type Namespace struct {
func (ns *Namespace) CountRunes(s any) (int, error) {
ss, err := cast.ToStringE(s)
if err != nil {
- return 0, _errors.Wrap(err, "Failed to convert content to string")
+ return 0, fmt.Errorf("Failed to convert content to string: %w", err)
}
counter := 0
@@ -65,7 +65,7 @@ func (ns *Namespace) CountRunes(s any) (int, error) {
func (ns *Namespace) RuneCount(s any) (int, error) {
ss, err := cast.ToStringE(s)
if err != nil {
- return 0, _errors.Wrap(err, "Failed to convert content to string")
+ return 0, fmt.Errorf("Failed to convert content to string: %w", err)
}
return utf8.RuneCountInString(ss), nil
}
@@ -74,12 +74,12 @@ func (ns *Namespace) RuneCount(s any) (int, error) {
func (ns *Namespace) CountWords(s any) (int, error) {
ss, err := cast.ToStringE(s)
if err != nil {
- return 0, _errors.Wrap(err, "Failed to convert content to string")
+ return 0, fmt.Errorf("Failed to convert content to string: %w", err)
}
isCJKLanguage, err := regexp.MatchString(`\p{Han}|\p{Hangul}|\p{Hiragana}|\p{Katakana}`, ss)
if err != nil {
- return 0, _errors.Wrap(err, "Failed to match regex pattern against string")
+ return 0, fmt.Errorf("Failed to match regex pattern against string: %w", err)
}
if !isCJKLanguage {
@@ -104,11 +104,11 @@ func (ns *Namespace) CountWords(s any) (int, error) {
func (ns *Namespace) Count(substr, s any) (int, error) {
substrs, err := cast.ToStringE(substr)
if err != nil {
- return 0, _errors.Wrap(err, "Failed to convert substr to string")
+ return 0, fmt.Errorf("Failed to convert substr to string: %w", err)
}
ss, err := cast.ToStringE(s)
if err != nil {
- return 0, _errors.Wrap(err, "Failed to convert s to string")
+ return 0, fmt.Errorf("Failed to convert s to string: %w", err)
}
return strings.Count(ss, substrs), nil
}
diff --git a/tpl/tplimpl/embedded/templates/server/error.html b/tpl/tplimpl/embedded/templates/server/error.html
new file mode 100644
index 000000000..e5c6d0cbf
--- /dev/null
+++ b/tpl/tplimpl/embedded/templates/server/error.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html class="no-js" lang="">
+ <head>
+ <meta charset="utf-8" />
+ <title>Hugo Server: Error</title>
+ <style type="text/css">
+ body {
+ font-family: "Muli", avenir, -apple-system, BlinkMacSystemFont,
+ "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji",
+ "Segoe UI Emoji", "Segoe UI Symbol";
+ font-size: 16px;
+ color: #48b685;
+ background-color: #2f1e2e;
+ }
+ main {
+ margin: auto;
+ width: 95%;
+ padding: 1rem;
+ }
+ .version {
+ color: #ccc;
+ padding: 1rem 0;
+ }
+ .stack {
+ margin-top: 4rem;
+ }
+ pre {
+ white-space: pre-wrap;
+ white-space: -moz-pre-wrap;
+ white-space: -pre-wrap;
+ white-space: -o-pre-wrap;
+ word-wrap: break-word;
+ }
+ .highlight {
+ overflow-x: auto;
+ margin-bottom: 1rem;
+ }
+ a {
+ color: #0594cb;
+ text-decoration: none;
+ }
+ a:hover {
+ color: #ccc;
+ }
+ </style>
+ </head>
+ <body>
+ <main>
+ {{ highlight .Error "apl" "linenos=false,noclasses=true,style=paraiso-dark" }}
+ {{ range $i, $e := .Files }}
+ {{ if not .ErrorContext }}
+ {{ continue }}
+ {{ end }}
+ {{ $params := printf "noclasses=true,style=paraiso-dark,linenos=table,hl_lines=%d,linenostart=%d" (add .ErrorContext.LinesPos 1) (sub .Position.LineNumber .ErrorContext.LinesPos) }}
+ {{ $lexer := .ErrorContext.ChromaLexer | default "go-html-template" }}
+ <h3><code>{{ path.Base .Position.Filename }}:</code></h3>
+ {{ highlight (delimit .ErrorContext.Lines "\n") $lexer $params }}
+ {{ end }}
+ <p class="version">{{ .Version }}</p>
+ <a href="">Reload Page</a>
+ </main>
+ </body>
+</html>
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index 4cee19a20..c092ff638 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -17,6 +17,7 @@ import (
"bytes"
"context"
"embed"
+ "fmt"
"io"
"io/fs"
"os"
@@ -42,7 +43,6 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugofs/files"
- "github.com/pkg/errors"
htmltemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/htmltemplate"
texttemplate "github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate"
@@ -551,14 +551,10 @@ func (t *templateHandler) addFileContext(templ tpl.Template, inerr error) error
}
defer f.Close()
- fe, ok := herrors.WithFileContext(inErr, info.realFilename, f, lineMatcher)
- if ok {
- return fe, true
- }
- return inErr, false
+ return herrors.NewFileError(info.realFilename, inErr).UpdateContent(f, lineMatcher), true
}
- inerr = errors.Wrap(inerr, "execute of template failed")
+ inerr = fmt.Errorf("execute of template failed: %w", inerr)
if err, ok := checkFilename(ts.info, inerr); ok {
return err
@@ -736,6 +732,7 @@ func (t *templateHandler) extractIdentifiers(line string) []string {
//go:embed embedded/templates/*
//go:embed embedded/templates/_default/*
+//go:embed embedded/templates/server/*
var embededTemplatesFs embed.FS
func (t *templateHandler) loadEmbedded() error {
@@ -755,10 +752,10 @@ func (t *templateHandler) loadEmbedded() error {
name := strings.TrimPrefix(filepath.ToSlash(path), "embedded/templates/")
templateName := name
- // For the render hooks it does not make sense to preseve the
+ // For the render hooks and the server templates it does not make sense to preseve the
// double _indternal double book-keeping,
// just add it if its now provided by the user.
- if !strings.Contains(path, "_default/_markup") {
+ if !strings.Contains(path, "_default/_markup") && !strings.HasPrefix(name, "server/") {
templateName = internalPathPrefix + name
}
diff --git a/tpl/tplimpl/template_ast_transformers.go b/tpl/tplimpl/template_ast_transformers.go
index 33461dc7d..dee1fd6c2 100644
--- a/tpl/tplimpl/template_ast_transformers.go
+++ b/tpl/tplimpl/template_ast_transformers.go
@@ -14,6 +14,7 @@
package tplimpl
import (
+ "fmt"
"regexp"
"strings"
@@ -22,10 +23,11 @@ import (
"github.com/gohugoio/hugo/tpl/internal/go_templates/texttemplate/parse"
+ "errors"
+
"github.com/gohugoio/hugo/common/maps"
"github.com/gohugoio/hugo/tpl"
"github.com/mitchellh/mapstructure"
- "github.com/pkg/errors"
)
type templateType int
@@ -239,14 +241,14 @@ func (c *templateContext) collectConfig(n *parse.PipeNode) {
}
if s, ok := cmd.Args[0].(*parse.StringNode); ok {
- errMsg := "failed to decode $_hugo_config in template"
+ errMsg := "failed to decode $_hugo_config in template: %w"
m, err := maps.ToStringMapE(s.Text)
if err != nil {
- c.err = errors.Wrap(err, errMsg)
+ c.err = fmt.Errorf(errMsg, err)
return
}
if err := mapstructure.WeakDecode(m, &c.t.parseInfo.Config); err != nil {
- c.err = errors.Wrap(err, errMsg)
+ c.err = fmt.Errorf(errMsg, err)
}
}
}
diff --git a/tpl/tplimpl/template_errors.go b/tpl/tplimpl/template_errors.go
index 06d895536..d553a12e9 100644
--- a/tpl/tplimpl/template_errors.go
+++ b/tpl/tplimpl/template_errors.go
@@ -14,8 +14,9 @@
package tplimpl
import (
+ "fmt"
+
"github.com/gohugoio/hugo/common/herrors"
- "github.com/pkg/errors"
"github.com/spf13/afero"
)
@@ -51,14 +52,13 @@ func (t templateInfo) resolveType() templateType {
}
func (info templateInfo) errWithFileContext(what string, err error) error {
- err = errors.Wrapf(err, what)
-
- err, _ = herrors.WithFileContextForFile(
- err,
- info.realFilename,
- info.filename,
- info.fs,
- herrors.SimpleLineMatcher)
+ err = fmt.Errorf(what+": %w", err)
+ fe := herrors.NewFileError(info.realFilename, err)
+ f, err := info.fs.Open(info.filename)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ return fe.UpdateContent(f, herrors.SimpleLineMatcher)
- return err
}
diff --git a/tpl/transform/remarshal.go b/tpl/transform/remarshal.go
index b5d682144..0ad54bb96 100644
--- a/tpl/transform/remarshal.go
+++ b/tpl/transform/remarshal.go
@@ -4,7 +4,7 @@ import (
"bytes"
"strings"
- "github.com/pkg/errors"
+ "errors"
"github.com/gohugoio/hugo/parser"
"github.com/gohugoio/hugo/parser/metadecoders"
diff --git a/tpl/transform/unmarshal.go b/tpl/transform/unmarshal.go
index 62682557c..340235fa4 100644
--- a/tpl/transform/unmarshal.go
+++ b/tpl/transform/unmarshal.go
@@ -14,6 +14,7 @@
package transform
import (
+ "fmt"
"io/ioutil"
"strings"
@@ -23,9 +24,10 @@ import (
"github.com/mitchellh/mapstructure"
+ "errors"
+
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/parser/metadecoders"
- "github.com/pkg/errors"
"github.com/spf13/cast"
)
@@ -54,7 +56,7 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
data = args[1]
decoder, err = decodeDecoder(m)
if err != nil {
- return nil, errors.WithMessage(err, "failed to decode options")
+ return nil, fmt.Errorf("failed to decode options: %w", err)
}
}
@@ -72,7 +74,7 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
return ns.cache.GetOrCreate(key, func() (any, error) {
f := metadecoders.FormatFromMediaType(r.MediaType())
if f == "" {
- return nil, errors.Errorf("MIME %q not supported", r.MediaType())
+ return nil, fmt.Errorf("MIME %q not supported", r.MediaType())
}
reader, err := r.ReadSeekCloser()
@@ -92,7 +94,7 @@ func (ns *Namespace) Unmarshal(args ...any) (any, error) {
dataStr, err := types.ToStringE(data)
if err != nil {
- return nil, errors.Errorf("type %T not supported", data)
+ return nil, fmt.Errorf("type %T not supported", data)
}
if dataStr == "" {
@@ -160,7 +162,7 @@ func stringToRune(v any) (rune, error) {
if i == 0 {
r = rr
} else {
- return 0, errors.Errorf("invalid character: %q", v)
+ return 0, fmt.Errorf("invalid character: %q", v)
}
}
diff --git a/tpl/urls/urls.go b/tpl/urls/urls.go
index 3d6f67789..bfbd7304f 100644
--- a/tpl/urls/urls.go
+++ b/tpl/urls/urls.go
@@ -22,7 +22,6 @@ import (
"github.com/gohugoio/hugo/common/urls"
"github.com/gohugoio/hugo/deps"
- _errors "github.com/pkg/errors"
"github.com/spf13/cast"
)
@@ -55,7 +54,7 @@ func (ns *Namespace) AbsURL(s any) (template.HTML, error) {
func (ns *Namespace) Parse(rawurl any) (*url.URL, error) {
s, err := cast.ToStringE(rawurl)
if err != nil {
- return nil, _errors.Wrap(err, "Error in Parse")
+ return nil, fmt.Errorf("Error in Parse: %w", err)
}
return url.Parse(s)