MM-18167: fix KV* helpers error handling (#12023)
* MM-18167: fix KV* helpers error handling Returning a `nil` `*model.AppError` does not make a `nil` `error` interface. As a consequence, all of the KV* helper methods would always appear to fail, even if the underlying API call was successful. Fix this mismatch by explicitly assigning `appErr` in the helpers and only ever returning a `nil` `error` interface. Extend unit tests to achieve 100% coverage of the associated files. In the long run, we must change all function signatures to return the `error` interface instead of the abomination that is returning `*model.AppError` today.
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
8677596c0d
Коммит
8afbe9c6a4
@@ -34,7 +34,12 @@ func (p *HelpersImpl) KVSetJSON(key string, value interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.API.KVSet(key, data)
|
||||
appErr := p.API.KVSet(key, data)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// KVCompareAndSetJSON is a wrapper around KVCompareAndSet to simplify atomically writing a JSON object to the key value store.
|
||||
@@ -56,7 +61,12 @@ func (p *HelpersImpl) KVCompareAndSetJSON(key string, oldValue interface{}, newV
|
||||
}
|
||||
}
|
||||
|
||||
return p.API.KVCompareAndSet(key, oldData, newData)
|
||||
set, appErr := p.API.KVCompareAndSet(key, oldData, newData)
|
||||
if appErr != nil {
|
||||
return set, appErr
|
||||
}
|
||||
|
||||
return set, nil
|
||||
}
|
||||
|
||||
// KVCompareAndDeleteJSON is a wrapper around KVCompareAndDelete to simplify atomically deleting a JSON object from the key value store.
|
||||
@@ -71,7 +81,12 @@ func (p *HelpersImpl) KVCompareAndDeleteJSON(key string, oldValue interface{}) (
|
||||
}
|
||||
}
|
||||
|
||||
return p.API.KVCompareAndDelete(key, oldData)
|
||||
deleted, appErr := p.API.KVCompareAndDelete(key, oldData)
|
||||
if appErr != nil {
|
||||
return deleted, appErr
|
||||
}
|
||||
|
||||
return deleted, nil
|
||||
}
|
||||
|
||||
// KVSetWithExpiryJSON is a wrapper around KVSetWithExpiry to simplify atomically writing a JSON object with expiry to the key value store.
|
||||
@@ -81,5 +96,10 @@ func (p *HelpersImpl) KVSetWithExpiryJSON(key string, value interface{}, expireI
|
||||
return err
|
||||
}
|
||||
|
||||
return p.API.KVSetWithExpiry(key, data, expireInSeconds)
|
||||
appErr := p.API.KVSetWithExpiry(key, data, expireInSeconds)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user