diff --git a/sdk/instance/backend.go b/sdk/instance/backend.go index 658cc76e0..36690b6f8 100644 --- a/sdk/instance/backend.go +++ b/sdk/instance/backend.go @@ -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) } diff --git a/sdk/runner/backend.go b/sdk/runner/backend.go index 15dde027e..d16d40fcf 100644 --- a/sdk/runner/backend.go +++ b/sdk/runner/backend.go @@ -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) } diff --git a/sdk/service/backend.go b/sdk/service/backend.go index 9fd0970ba..22ad10073 100644 --- a/sdk/service/backend.go +++ b/sdk/service/backend.go @@ -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) } @@ -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 {