Преглед изворни кода

changed to plain errors further down the alerting validation model so error did not get double wrapping in ValidationError

Torkel Ödegaard пре 7 година
родитељ
комит
ba67dc7689
2 измењених фајлова са 6 додато и 5 уклоњено
  1. 5 4
      pkg/services/alerting/conditions/evaluator.go
  2. 1 1
      pkg/services/alerting/rule.go

+ 5 - 4
pkg/services/alerting/conditions/evaluator.go

@@ -2,6 +2,7 @@ package conditions
 
 
 import (
 import (
 	"encoding/json"
 	"encoding/json"
+	"fmt"
 
 
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/null"
 	"github.com/grafana/grafana/pkg/components/simplejson"
 	"github.com/grafana/grafana/pkg/components/simplejson"
@@ -31,12 +32,12 @@ type ThresholdEvaluator struct {
 func newThresholdEvaluator(typ string, model *simplejson.Json) (*ThresholdEvaluator, error) {
 func newThresholdEvaluator(typ string, model *simplejson.Json) (*ThresholdEvaluator, error) {
 	params := model.Get("params").MustArray()
 	params := model.Get("params").MustArray()
 	if len(params) == 0 {
 	if len(params) == 0 {
-		return nil, alerting.ValidationError{Reason: "Evaluator missing threshold parameter"}
+		return nil, fmt.Errorf("Evaluator missing threshold parameter")
 	}
 	}
 
 
 	firstParam, ok := params[0].(json.Number)
 	firstParam, ok := params[0].(json.Number)
 	if !ok {
 	if !ok {
-		return nil, alerting.ValidationError{Reason: "Evaluator has invalid parameter"}
+		return nil, fmt.Errorf("Evaluator has invalid parameter")
 	}
 	}
 
 
 	defaultEval := &ThresholdEvaluator{Type: typ}
 	defaultEval := &ThresholdEvaluator{Type: typ}
@@ -107,7 +108,7 @@ func (e *RangedEvaluator) Eval(reducedValue null.Float) bool {
 func NewAlertEvaluator(model *simplejson.Json) (AlertEvaluator, error) {
 func NewAlertEvaluator(model *simplejson.Json) (AlertEvaluator, error) {
 	typ := model.Get("type").MustString()
 	typ := model.Get("type").MustString()
 	if typ == "" {
 	if typ == "" {
-		return nil, alerting.ValidationError{Reason: "Evaluator missing type property"}
+		return nil, fmt.Errorf("Evaluator missing type property")
 	}
 	}
 
 
 	if inSlice(typ, defaultTypes) {
 	if inSlice(typ, defaultTypes) {
@@ -122,7 +123,7 @@ func NewAlertEvaluator(model *simplejson.Json) (AlertEvaluator, error) {
 		return &NoValueEvaluator{}, nil
 		return &NoValueEvaluator{}, nil
 	}
 	}
 
 
-	return nil, alerting.ValidationError{Reason: "Evaluator invalid evaluator type: " + typ}
+	return nil, fmt.Errorf("Evaluator invalid evaluator type: %s", typ)
 }
 }
 
 
 func inSlice(a string, list []string) bool {
 func inSlice(a string, list []string) bool {

+ 1 - 1
pkg/services/alerting/rule.go

@@ -128,7 +128,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
 	}
 	}
 
 
 	if len(model.Conditions) == 0 {
 	if len(model.Conditions) == 0 {
-		return nil, fmt.Errorf("Alert is missing conditions")
+		return nil, ValidationError{Reason: "Alert is missing conditions"}
 	}
 	}
 
 
 	return model, nil
 	return model, nil