118: queryRecords should return [] when no matching records exist, not an error (#121)
Some checks failed
Pull Request Labeler / triage (push) Successful in 7s
Lint / Run flake8 on python integration tests (push) Failing after 31s
Tests / cleanup-runs (push) Has been skipped
CodeQL / Analyze (go) (push) Failing after 2m29s
Lint / Run golangci-lint (push) Successful in 5m43s
Run Gosec / Gosec (push) Failing after 7m38s
Tests / test-unit-cover (push) Failing after 7m49s
Tests / test-rpc (push) Failing after 3m53s
Tests / sdk_tests (push) Failing after 3m14s
Tests / test-importer (push) Failing after 13m15s

Whenever a key is used which doesn't exist in the DB at all, an error is returned like this:

```
[
  {
    message: `rpc error: code = Unknown desc = store doesn't have key: "\\atypeApplicationRecord"`,
    path: [ 'queryRecords' ]
  }
]
```

That doesn't make any sense, as it is not an error to find out that the thing you asked for does not exist.  This changes it to return an empty list.

Reviewed-on: cerc-io/laconicd#121
Reviewed-by: David Boreham <dboreham@noreply.git.vdb.to>
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
This commit is contained in:
Thomas E Lackey 2023-11-28 20:41:28 +00:00 committed by Thomas E Lackey
parent d57743bfd5
commit 0adc932400

View File

@ -20,6 +20,7 @@ import (
auth "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bank "github.com/cosmos/cosmos-sdk/x/bank/keeper"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/tendermint/tendermint/libs/log"
)
var (
@ -96,6 +97,11 @@ func NewKeeper(cdc codec.BinaryCodec, accountKeeper auth.AccountKeeper, bankKeep
}
}
// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", types.ModuleName)
}
// GetRecordIndexKey Generates Bond ID -> Bond index key.
func GetRecordIndexKey(id string) []byte {
return append(PrefixCIDToRecordIndex, []byte(id)...)
@ -389,7 +395,8 @@ func (k Keeper) GetAttributeMapping(ctx sdk.Context, key []byte) ([]string, erro
store := ctx.KVStore(k.storeKey)
if !store.Has(key) {
return nil, fmt.Errorf("store doesn't have key: %q", key)
k.Logger(ctx).Debug(fmt.Sprintf("store doesn't have key: %q", key))
return []string{}, nil
}
var recordIds []string