mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
backend: replace /pkg/errors with errutil (#17065)
This commit is contained in:
parent
fdd421e24c
commit
c55e6016bf
2
go.mod
2
go.mod
@ -48,7 +48,7 @@ require (
|
|||||||
github.com/onsi/gomega v1.5.0 // indirect
|
github.com/onsi/gomega v1.5.0 // indirect
|
||||||
github.com/opentracing/opentracing-go v1.1.0
|
github.com/opentracing/opentracing-go v1.1.0
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1 // indirect
|
||||||
github.com/prometheus/client_golang v0.9.2
|
github.com/prometheus/client_golang v0.9.2
|
||||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
|
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
|
||||||
github.com/prometheus/common v0.2.0
|
github.com/prometheus/common v0.2.0
|
||||||
|
@ -12,9 +12,9 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
m "github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"github.com/pkg/errors"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
gomail "gopkg.in/mail.v2"
|
gomail "gopkg.in/mail.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,11 +38,11 @@ func (ns *NotificationService) send(msg *Message) (int, error) {
|
|||||||
|
|
||||||
e := dialer.DialAndSend(m)
|
e := dialer.DialAndSend(m)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = errors.Wrapf(e, "Failed to send notification to email address: %s", address)
|
err = errutil.Wrapf(e, "Failed to send notification to email address: %s", address)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
num += 1
|
num++
|
||||||
}
|
}
|
||||||
|
|
||||||
return num, err
|
return num, err
|
||||||
@ -83,9 +83,9 @@ func (ns *NotificationService) createDialer() (*gomail.Dialer, error) {
|
|||||||
return d, nil
|
return d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NotificationService) buildEmailMessage(cmd *m.SendEmailCommand) (*Message, error) {
|
func (ns *NotificationService) buildEmailMessage(cmd *models.SendEmailCommand) (*Message, error) {
|
||||||
if !ns.Cfg.Smtp.Enabled {
|
if !ns.Cfg.Smtp.Enabled {
|
||||||
return nil, m.ErrSmtpNotEnabled
|
return nil, models.ErrSmtpNotEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
|
@ -3,8 +3,9 @@ package dashboards
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/pkg/errors"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DashboardProvisionerImpl struct {
|
type DashboardProvisionerImpl struct {
|
||||||
@ -18,13 +19,13 @@ func NewDashboardProvisionerImpl(configDirectory string) (*DashboardProvisionerI
|
|||||||
configs, err := cfgReader.readConfig()
|
configs, err := cfgReader.readConfig()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Failed to read dashboards config")
|
return nil, errutil.Wrap("Failed to read dashboards config", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileReaders, err := getFileReaders(configs, logger)
|
fileReaders, err := getFileReaders(configs, logger)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Failed to initialize file readers")
|
return nil, errutil.Wrap("Failed to initialize file readers", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d := &DashboardProvisionerImpl{
|
d := &DashboardProvisionerImpl{
|
||||||
@ -39,7 +40,7 @@ func (provider *DashboardProvisionerImpl) Provision() error {
|
|||||||
for _, reader := range provider.fileReaders {
|
for _, reader := range provider.fileReaders {
|
||||||
err := reader.startWalkingDisk()
|
err := reader.startWalkingDisk()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "Failed to provision config %v", reader.Cfg.Name)
|
return errutil.Wrapf(err, "Failed to provision config %v", reader.Cfg.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ func getFileReaders(configs []*DashboardsAsConfig, logger log.Logger) ([]*fileRe
|
|||||||
case "file":
|
case "file":
|
||||||
fileReader, err := NewDashboardFileReader(config, logger.New("type", config.Type, "name", config.Name))
|
fileReader, err := NewDashboardFileReader(config, logger.New("type", config.Type, "name", config.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "Failed to create file reader for config %v", config.Name)
|
return nil, errutil.Wrapf(err, "Failed to create file reader for config %v", config.Name)
|
||||||
}
|
}
|
||||||
readers = append(readers, fileReader)
|
readers = append(readers, fileReader)
|
||||||
default:
|
default:
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/pkg/errors"
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/registry"
|
"github.com/grafana/grafana/pkg/registry"
|
||||||
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
|
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
|
||||||
@ -103,20 +103,20 @@ func (ps *provisioningServiceImpl) Run(ctx context.Context) error {
|
|||||||
func (ps *provisioningServiceImpl) ProvisionDatasources() error {
|
func (ps *provisioningServiceImpl) ProvisionDatasources() error {
|
||||||
datasourcePath := path.Join(ps.Cfg.ProvisioningPath, "datasources")
|
datasourcePath := path.Join(ps.Cfg.ProvisioningPath, "datasources")
|
||||||
err := ps.provisionDatasources(datasourcePath)
|
err := ps.provisionDatasources(datasourcePath)
|
||||||
return errors.Wrap(err, "Datasource provisioning error")
|
return errutil.Wrap("Datasource provisioning error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *provisioningServiceImpl) ProvisionNotifications() error {
|
func (ps *provisioningServiceImpl) ProvisionNotifications() error {
|
||||||
alertNotificationsPath := path.Join(ps.Cfg.ProvisioningPath, "notifiers")
|
alertNotificationsPath := path.Join(ps.Cfg.ProvisioningPath, "notifiers")
|
||||||
err := ps.provisionNotifiers(alertNotificationsPath)
|
err := ps.provisionNotifiers(alertNotificationsPath)
|
||||||
return errors.Wrap(err, "Alert notification provisioning error")
|
return errutil.Wrap("Alert notification provisioning error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps *provisioningServiceImpl) ProvisionDashboards() error {
|
func (ps *provisioningServiceImpl) ProvisionDashboards() error {
|
||||||
dashboardPath := path.Join(ps.Cfg.ProvisioningPath, "dashboards")
|
dashboardPath := path.Join(ps.Cfg.ProvisioningPath, "dashboards")
|
||||||
dashProvisioner, err := ps.newDashboardProvisioner(dashboardPath)
|
dashProvisioner, err := ps.newDashboardProvisioner(dashboardPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed to create provisioner")
|
return errutil.Wrap("Failed to create provisioner", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ps.mutex.Lock()
|
ps.mutex.Lock()
|
||||||
@ -127,7 +127,7 @@ func (ps *provisioningServiceImpl) ProvisionDashboards() error {
|
|||||||
if err := dashProvisioner.Provision(); err != nil {
|
if err := dashProvisioner.Provision(); err != nil {
|
||||||
// If we fail to provision with the new provisioner, mutex will unlock and the polling we restart with the
|
// If we fail to provision with the new provisioner, mutex will unlock and the polling we restart with the
|
||||||
// old provisioner as we did not switch them yet.
|
// old provisioner as we did not switch them yet.
|
||||||
return errors.Wrap(err, "Failed to provision dashboards")
|
return errutil.Wrap("Failed to provision dashboards", err)
|
||||||
}
|
}
|
||||||
ps.dashboardProvisioner = dashProvisioner
|
ps.dashboardProvisioner = dashProvisioner
|
||||||
return nil
|
return nil
|
||||||
|
@ -11,10 +11,11 @@
|
|||||||
package values
|
package values
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pkg/errors"
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/util/errutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IntValue struct {
|
type IntValue struct {
|
||||||
@ -33,7 +34,7 @@ func (val *IntValue) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
}
|
}
|
||||||
val.Raw = interpolated.raw
|
val.Raw = interpolated.raw
|
||||||
val.value, err = strconv.Atoi(interpolated.value)
|
val.value, err = strconv.Atoi(interpolated.value)
|
||||||
return errors.Wrap(err, "cannot convert value int")
|
return errutil.Wrap("cannot convert value int", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (val *IntValue) Value() int {
|
func (val *IntValue) Value() int {
|
||||||
|
@ -1,11 +1,29 @@
|
|||||||
package errutil
|
package errutil
|
||||||
|
|
||||||
import "golang.org/x/xerrors"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
)
|
||||||
|
|
||||||
// Wrap is a simple wrapper around Errorf that is doing error wrapping. You can read how that works in
|
// Wrap is a simple wrapper around Errorf that is doing error wrapping. You can read how that works in
|
||||||
// https://godoc.org/golang.org/x/xerrors#Errorf but its API is very implicit which is a reason for this wrapper.
|
// https://godoc.org/golang.org/x/xerrors#Errorf but its API is very implicit which is a reason for this wrapper.
|
||||||
// There is also a discussion (https://github.com/golang/go/issues/29934) where many comments make arguments for such
|
// There is also a discussion (https://github.com/golang/go/issues/29934) where many comments make arguments for such
|
||||||
// wrapper so hopefully it will be added in the standard lib later.
|
// wrapper so hopefully it will be added in the standard lib later.
|
||||||
func Wrap(message string, err error) error {
|
func Wrap(message string, err error) error {
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return xerrors.Errorf("%v: %w", message, err)
|
return xerrors.Errorf("%v: %w", message, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrapf is a simple wrapper around Errorf that is doing error wrapping
|
||||||
|
// Wrapf allows you to send a format and args instead of just a message.
|
||||||
|
func Wrapf(err error, message string, a ...interface{}) error {
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return Wrap(fmt.Sprintf(message, a...), err)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user