Chore: Drop xerrors dependency (#26718)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package alerting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -16,7 +17,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/rendering"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
// AlertEngine is the background process that
|
||||
@@ -215,9 +215,9 @@ func (e *AlertEngine) processJob(attemptID int, attemptChan chan int, cancelChan
|
||||
evalContext.Rule.State = evalContext.GetNewState()
|
||||
if err := e.resultHandler.handle(evalContext); err != nil {
|
||||
switch {
|
||||
case xerrors.Is(err, context.Canceled):
|
||||
case errors.Is(err, context.Canceled):
|
||||
e.log.Debug("Result handler returned context.Canceled")
|
||||
case xerrors.Is(err, context.DeadlineExceeded):
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
e.log.Debug("Result handler returned context.DeadlineExceeded")
|
||||
default:
|
||||
e.log.Error("Failed to handle result", "err", err)
|
||||
|
||||
@@ -271,7 +271,7 @@ func TestAlertRuleExtraction(t *testing.T) {
|
||||
|
||||
Convey("Should fail on save", func() {
|
||||
_, err := extractor.GetAlerts()
|
||||
So(err.Error(), ShouldEqual, "Alert validation error: Panel id is not correct, alertName=Influxdb, panelId=1")
|
||||
So(err.Error(), ShouldEqual, "alert validation error: Panel id is not correct, alertName=Influxdb, panelId=1")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestSlackNotifier(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err = NewSlackNotifier(model)
|
||||
So(err, ShouldBeError, "Alert validation error: Could not find url property in settings")
|
||||
So(err, ShouldBeError, "alert validation error: Could not find url property in settings")
|
||||
})
|
||||
|
||||
//nolint:goconst
|
||||
@@ -157,7 +157,7 @@ func TestSlackNotifier(t *testing.T) {
|
||||
|
||||
_, err = NewSlackNotifier(model)
|
||||
|
||||
So(err, ShouldBeError, "Alert validation error: Recipient on invalid format: \"#open tsdb\"")
|
||||
So(err, ShouldBeError, "alert validation error: Recipient on invalid format: \"#open tsdb\"")
|
||||
})
|
||||
|
||||
Convey("with user recipient with spaces should return an error", func() {
|
||||
@@ -177,7 +177,7 @@ func TestSlackNotifier(t *testing.T) {
|
||||
|
||||
_, err = NewSlackNotifier(model)
|
||||
|
||||
So(err, ShouldBeError, "Alert validation error: Recipient on invalid format: \"@user name\"")
|
||||
So(err, ShouldBeError, "alert validation error: Recipient on invalid format: \"@user name\"")
|
||||
})
|
||||
|
||||
Convey("with user recipient with uppercase letters should return an error", func() {
|
||||
@@ -197,7 +197,7 @@ func TestSlackNotifier(t *testing.T) {
|
||||
|
||||
_, err = NewSlackNotifier(model)
|
||||
|
||||
So(err, ShouldBeError, "Alert validation error: Recipient on invalid format: \"@User\"")
|
||||
So(err, ShouldBeError, "alert validation error: Recipient on invalid format: \"@User\"")
|
||||
})
|
||||
|
||||
Convey("with Slack ID for recipient should work", func() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package alerting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
@@ -9,7 +10,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
"github.com/grafana/grafana/pkg/services/rendering"
|
||||
@@ -101,9 +101,9 @@ func (handler *defaultResultHandler) handle(evalContext *EvalContext) error {
|
||||
|
||||
if err := handler.notifier.SendIfNeeded(evalContext); err != nil {
|
||||
switch {
|
||||
case xerrors.Is(err, context.Canceled):
|
||||
case errors.Is(err, context.Canceled):
|
||||
handler.log.Debug("handler.notifier.SendIfNeeded returned context.Canceled")
|
||||
case xerrors.Is(err, context.DeadlineExceeded):
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
handler.log.Debug("handler.notifier.SendIfNeeded returned context.DeadlineExceeded")
|
||||
default:
|
||||
handler.log.Error("handler.notifier.SendIfNeeded failed", "err", err)
|
||||
|
||||
@@ -66,10 +66,10 @@ func (e ValidationError) Error() string {
|
||||
}
|
||||
|
||||
if e.Err != nil {
|
||||
return fmt.Sprintf("Alert validation error: %s%s", e.Err.Error(), extraInfo)
|
||||
return fmt.Sprintf("alert validation error: %s%s", e.Err.Error(), extraInfo)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Alert validation error: %s", extraInfo)
|
||||
return fmt.Sprintf("alert validation error: %s", extraInfo)
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -215,7 +215,7 @@ func TestAlertRuleModel(t *testing.T) {
|
||||
|
||||
_, err := NewRuleFromDBAlert(alert)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(err.Error(), ShouldEqual, "Alert validation error: Neither id nor uid is specified in 'notifications' block, type assertion to string failed AlertId: 1 PanelId: 1 DashboardId: 1")
|
||||
So(err.Error(), ShouldEqual, "alert validation error: Neither id nor uid is specified in 'notifications' block, type assertion to string failed AlertId: 1 PanelId: 1 DashboardId: 1")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dashboards
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
@@ -10,7 +11,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/guardian"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
func TestDashboardService(t *testing.T) {
|
||||
@@ -145,12 +145,12 @@ func TestDashboardService(t *testing.T) {
|
||||
})
|
||||
|
||||
bus.AddHandler("test", func(cmd *models.ValidateDashboardAlertsCommand) error {
|
||||
return xerrors.New("Alert validation error")
|
||||
return fmt.Errorf("alert validation error")
|
||||
})
|
||||
|
||||
dto.Dashboard = models.NewDashboard("Dash")
|
||||
_, err := service.SaveDashboard(dto, false)
|
||||
So(err.Error(), ShouldEqual, "Alert validation error")
|
||||
So(err.Error(), ShouldEqual, "alert validation error")
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
@@ -136,7 +135,7 @@ func readConfig(configFile string) (*Config, error) {
|
||||
}
|
||||
|
||||
if len(result.Servers) == 0 {
|
||||
return nil, xerrors.New("LDAP enabled but no LDAP servers defined in config file")
|
||||
return nil, fmt.Errorf("LDAP enabled but no LDAP servers defined in config file")
|
||||
}
|
||||
|
||||
// set default org id
|
||||
@@ -164,11 +163,11 @@ func assertNotEmptyCfg(val interface{}, propName string) error {
|
||||
switch v := val.(type) {
|
||||
case string:
|
||||
if v == "" {
|
||||
return xerrors.Errorf("LDAP config file is missing option: %v", propName)
|
||||
return fmt.Errorf("LDAP config file is missing option: %q", propName)
|
||||
}
|
||||
case []string:
|
||||
if len(v) == 0 {
|
||||
return xerrors.Errorf("LDAP config file is missing option: %v", propName)
|
||||
return fmt.Errorf("LDAP config file is missing option: %q", propName)
|
||||
}
|
||||
default:
|
||||
fmt.Println("unknown")
|
||||
|
||||
@@ -321,7 +321,7 @@ func TestNotificationAsConfig(t *testing.T) {
|
||||
cfgProvider := &configReader{log: log.New("test logger")}
|
||||
_, err := cfgProvider.readConfig(incorrectSettings)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(err.Error(), ShouldEqual, "Alert validation error: Could not find url property in settings")
|
||||
So(err.Error(), ShouldEqual, "alert validation error: Could not find url property in settings")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user