diff --git a/errors/errors.go b/errors/errors.go index 530e938..9a1791d 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -35,8 +35,8 @@ type ValidationError string func NewValidationError(str string) error { return ValidationError(str) } func (e ValidationError) Error() string { return string(e) } -// StaleDataError is returned when a rule is modified but the -// underlying data has changed and the rquest is no longer valid. +// StaleDataError is returned when a rule modification is attempted but the +// underlying data has changed and the change is no longer valid. type StaleDataError string // NewStaleDataError creates a new version mismatch error. diff --git a/rules/store/kv/store.go b/rules/store/kv/store.go index 5a05a94..6f54140 100644 --- a/rules/store/kv/store.go +++ b/rules/store/kv/store.go @@ -97,12 +97,12 @@ func (s *store) WriteRuleSet(rs rules.MutableRuleSet) error { } conditions, ops := []kv.Condition{rsCond}, []kv.Op{rsOp} _, err = s.kvStore.Commit(conditions, ops) - if err != nil { - if err == kv.ErrConditionCheckFailed { - err = merrors.NewStaleDataError(err.Error()) - } + switch err { + case kv.ErrConditionCheckFailed: + return merrors.NewStaleDataError(err.Error()) + default: + return err } - return err } func (s *store) WriteAll(nss *rules.Namespaces, rs rules.MutableRuleSet) error {