refactor (template): move from github.com/pkg/errors to 'errors' and 'fmt' (#10818)

Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>

Co-authored-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
This commit is contained in:
Matthieu MOREL 2022-06-08 10:44:08 +02:00 committed by GitHub
parent 15aeadedbe
commit 554f3f32f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -16,6 +16,7 @@ package template
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
html_template "html/template" html_template "html/template"
"math" "math"
@ -28,7 +29,6 @@ import (
"time" "time"
"github.com/grafana/regexp" "github.com/grafana/regexp"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
@ -375,7 +375,7 @@ func (te Expander) Expand() (result string, resultErr error) {
var ok bool var ok bool
resultErr, ok = r.(error) resultErr, ok = r.(error)
if !ok { if !ok {
resultErr = errors.Errorf("panic expanding template %v: %v", te.name, r) resultErr = fmt.Errorf("panic expanding template %v: %v", te.name, r)
} }
} }
if resultErr != nil { if resultErr != nil {
@ -389,12 +389,12 @@ func (te Expander) Expand() (result string, resultErr error) {
tmpl.Option(te.options...) tmpl.Option(te.options...)
tmpl, err := tmpl.Parse(te.text) tmpl, err := tmpl.Parse(te.text)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "error parsing template %v", te.name) return "", fmt.Errorf("error parsing template %v: %w", te.name, err)
} }
var buffer bytes.Buffer var buffer bytes.Buffer
err = tmpl.Execute(&buffer, te.data) err = tmpl.Execute(&buffer, te.data)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "error executing template %v", te.name) return "", fmt.Errorf("error executing template %v: %w", te.name, err)
} }
return buffer.String(), nil return buffer.String(), nil
} }
@ -406,7 +406,7 @@ func (te Expander) ExpandHTML(templateFiles []string) (result string, resultErr
var ok bool var ok bool
resultErr, ok = r.(error) resultErr, ok = r.(error)
if !ok { if !ok {
resultErr = errors.Errorf("panic expanding template %s: %v", te.name, r) resultErr = fmt.Errorf("panic expanding template %s: %v", te.name, r)
} }
} }
}() }()
@ -422,18 +422,18 @@ func (te Expander) ExpandHTML(templateFiles []string) (result string, resultErr
}) })
tmpl, err := tmpl.Parse(te.text) tmpl, err := tmpl.Parse(te.text)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "error parsing template %v", te.name) return "", fmt.Errorf("error parsing template %v: %w", te.name, err)
} }
if len(templateFiles) > 0 { if len(templateFiles) > 0 {
_, err = tmpl.ParseFiles(templateFiles...) _, err = tmpl.ParseFiles(templateFiles...)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "error parsing template files for %v", te.name) return "", fmt.Errorf("error parsing template files for %v: %w", te.name, err)
} }
} }
var buffer bytes.Buffer var buffer bytes.Buffer
err = tmpl.Execute(&buffer, te.data) err = tmpl.Execute(&buffer, te.data)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "error executing template %v", te.name) return "", fmt.Errorf("error executing template %v: %w", te.name, err)
} }
return buffer.String(), nil return buffer.String(), nil
} }