fix stuttering StoreValueUnsetError

This commit is contained in:
Thomas Tendyck 2022-03-25 12:49:22 +01:00 committed by Thomas Tendyck
parent 5660f813f0
commit b1818ba089
5 changed files with 9 additions and 9 deletions

View File

@ -73,7 +73,7 @@ func (s *EtcdStore) Get(request string) ([]byte, error) {
return nil, err
}
if values.Count == 0 {
return nil, &StoreValueUnsetError{requestedValue: request}
return nil, &ValueUnsetError{requestedValue: request}
}
if values.Count == 1 {
return values.Kvs[0].Value, nil
@ -150,7 +150,7 @@ func (t *EtcdTransaction) Get(request string) ([]byte, error) {
return value, nil
}
if _, ok := t.dataDelete[request]; ok {
return nil, &StoreValueUnsetError{requestedValue: request}
return nil, &ValueUnsetError{requestedValue: request}
}
return t.store.Get(request)
}

View File

@ -30,7 +30,7 @@ func (s *StdStore) Get(request string) ([]byte, error) {
if ok {
return []byte(value), nil
}
return nil, &StoreValueUnsetError{requestedValue: request}
return nil, &ValueUnsetError{requestedValue: request}
}
// Put saves a value in StdStore by Type and Name.
@ -119,7 +119,7 @@ func (t *stdTransaction) Get(request string) ([]byte, error) {
if value, ok := t.data[request]; ok {
return []byte(value), nil
}
return nil, &StoreValueUnsetError{requestedValue: request}
return nil, &ValueUnsetError{requestedValue: request}
}
// Put saves a value.

View File

@ -44,12 +44,12 @@ type Iterator interface {
HasNext() bool
}
// StoreValueUnsetError is an error raised by unset values in the store.
type StoreValueUnsetError struct {
// ValueUnsetError is an error raised by unset values in the store.
type ValueUnsetError struct {
requestedValue string
}
// Error implements the Error interface.
func (s *StoreValueUnsetError) Error() string {
func (s *ValueUnsetError) Error() string {
return fmt.Sprintf("store: requested value not set: %s", s.requestedValue)
}

View File

@ -65,7 +65,7 @@ func testBasic(t *testing.T) {
_, err = store.Get("invalid:key")
assert.Error(err)
var unsetErr *StoreValueUnsetError
var unsetErr *ValueUnsetError
assert.ErrorAs(err, &unsetErr)
assert.NoError(store.Delete("test:input"))
assert.NoError(store.Delete("another:input"))

View File

@ -107,7 +107,7 @@ func (s StoreWrapper) GetPeers() ([]peer.Peer, error) {
// Should be called in a transaction together with Add/Remove operation(s).
func (s StoreWrapper) IncrementPeersResourceVersion() error {
val, err := s.GetPeersResourceVersion()
var unsetErr *store.StoreValueUnsetError
var unsetErr *store.ValueUnsetError
if errors.As(err, &unsetErr) {
val = 0
} else if err != nil {