From ef00f8ac3d762e4e0997a49c16808bb7fe81b661 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Tue, 22 Jun 2021 13:19:12 +0200 Subject: [PATCH] fix(kwallet): empty wallet key query When querying a key in an empty kwallet wallet, we receive the following error: ``` Error: unexpected end of JSON input ``` This is because the `k.wallet.ReadEntry` returns empty bytes and no error. Hence we should handle a case for empty bytes. Reference: https://github.com/cosmos/cosmos-sdk/issues/9562 --- kwallet.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kwallet.go b/kwallet.go index 1e5a16e..7dd3508 100644 --- a/kwallet.go +++ b/kwallet.go @@ -90,6 +90,10 @@ func (k *kwalletKeyring) Get(key string) (Item, error) { if err != nil { return Item{}, err } + if len(data) == 0 { + return Item{}, ErrKeyNotFound + } + item := Item{} err = json.Unmarshal(data, &item)