Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return not found error in backend get functions when resource doesn't exist #1510

Merged
merged 2 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sdk/instance/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func (s *Backend) FetchOrCreate(request cosmostypes.Request, serviceHash hash.Ha
// Get returns the instance that matches given hash.
func (s *Backend) Get(request cosmostypes.Request, hash hash.Hash) (*instance.Instance, error) {
var i *instance.Instance
value := request.KVStore(s.storeKey).Get(hash)
store := request.KVStore(s.storeKey)
if !store.Has(hash) {
return nil, fmt.Errorf("instance %q not found", hash)
}
value := store.Get(hash)
return i, codec.UnmarshalBinaryBare(value, &i)
}

Expand Down
6 changes: 5 additions & 1 deletion sdk/runner/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ func (s *Backend) Delete(request cosmostypes.Request, msg *msgDeleteRunner) erro

// Get returns the runner that matches given hash.
func (s *Backend) Get(request cosmostypes.Request, hash hash.Hash) (*runner.Runner, error) {
store := request.KVStore(s.storeKey)
if !store.Has(hash) {
return nil, fmt.Errorf("runner %q not found", hash)
}
value := store.Get(hash)
var run *runner.Runner
value := request.KVStore(s.storeKey).Get(hash)
return run, codec.UnmarshalBinaryBare(value, &run)
}

Expand Down
7 changes: 5 additions & 2 deletions sdk/service/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ func (s *Backend) Create(request cosmostypes.Request, msg *msgCreateService) (*s
// Get returns the service that matches given hash.
func (s *Backend) Get(request cosmostypes.Request, hash hash.Hash) (*service.Service, error) {
var sv *service.Service
value := request.KVStore(s.storeKey).Get(hash)
store := request.KVStore(s.storeKey)
if !store.Has(hash) {
return nil, fmt.Errorf("service %q not found", hash)
}
value := store.Get(hash)
return sv, codec.UnmarshalBinaryBare(value, &sv)
}

Expand All @@ -137,7 +141,6 @@ func (s *Backend) List(request cosmostypes.Request) ([]*service.Service, error)
services []*service.Service
iter = request.KVStore(s.storeKey).Iterator(nil, nil)
)

for iter.Valid() {
var sv *service.Service
if err := codec.UnmarshalBinaryBare(iter.Value(), &sv); err != nil {
Expand Down