Skip to content

Commit

Permalink
Merge pull request #663 from mackerelio/fix-validate-bug
Browse files Browse the repository at this point in the history
fix unintentionally return in validateRules
  • Loading branch information
rmatsuoka authored Nov 22, 2024
2 parents 4c34333 + f038753 commit d45e294
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions monitors/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,19 @@ func isSameMonitor(a mackerel.Monitor, b mackerel.Monitor, flagNameUniquenessEna
return "", false
}

func validateRuleAnomalyDetectionScopes(v reflect.Value, label string) (bool, error) {
func validateRuleAnomalyDetectionScopes(v reflect.Value, label string) error {
f := "Scopes"
vf := v.FieldByName("Scopes")
if !vf.IsValid() {
return false, fmt.Errorf("Monitor '%s' should have '%s': %s", label, f, v.FieldByName(f).Interface())
return fmt.Errorf("Monitor '%s' should have '%s': %s", label, f, v.FieldByName(f).Interface())
}
scopes, ok := vf.Interface().([]string)
if !ok {
return false, fmt.Errorf("Monitor '%s' has invalid '%s': %s", label, f, v.FieldByName(f).Interface())
return fmt.Errorf("Monitor '%s' has invalid '%s': %s", label, f, v.FieldByName(f).Interface())
} else if len(scopes) == 0 {
return false, fmt.Errorf("Monitor '%s' has empty '%s'", label, f)
return fmt.Errorf("Monitor '%s' has empty '%s'", label, f)
}
return true, nil
return nil
}

func validateRules(monitors []mackerel.Monitor, label string) (bool, error) {
Expand Down Expand Up @@ -305,7 +305,9 @@ func validateRules(monitors []mackerel.Monitor, label string) (bool, error) {
return false, fmt.Errorf("Monitor '%s' should have '%s': %s", label, f, v.FieldByName(f).Interface())
}
}
return validateRuleAnomalyDetectionScopes(v, label)
if err := validateRuleAnomalyDetectionScopes(v, label); err != nil {
return false, err
}
case *mackerel.MonitorConnectivity:
default:
return false, fmt.Errorf("Unknown type is found: %s", m.MonitorType())
Expand Down

0 comments on commit d45e294

Please sign in to comment.