Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-02 17:07:52 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-06 20:43:22 +0300
commitf2946da9e806c2bafbdd26707fe339db79bd980b (patch)
treeb5609317a861ea5f399e094e1b9287ca71dc22d1 /tpl/strings
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/strings')
-rw-r--r--tpl/strings/strings.go14
1 files changed, 7 insertions, 7 deletions
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
}