Fix #123: Deduplicate result errors

This commit is contained in:
TwinProduction
2021-06-05 18:50:24 -04:00
parent 5e00752c5a
commit 8997eeef05
5 changed files with 50 additions and 8 deletions

View File

@ -25,7 +25,7 @@ type Result struct {
Duration time.Duration `json:"duration"`
// Errors encountered during the evaluation of the service's health
Errors []string `json:"errors"`
Errors []string `json:"errors"` // XXX: find a way to filter out duplicate errors
// ConditionResults results of the service's conditions
ConditionResults []*ConditionResult `json:"conditionResults"`
@ -46,3 +46,15 @@ type Result struct {
// and sets it to nil after the evaluation has been completed.
body []byte
}
// AddError adds an error to the result's list of errors.
// It also ensures that there are no duplicates.
func (r *Result) AddError(error string) {
for _, resultError := range r.Errors {
if resultError == error {
// If the error already exists, don't add it
return
}
}
r.Errors = append(r.Errors, error)
}