From 1f04826b078724679849c6777d7eca6c49860c27 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Tue, 20 Aug 2019 12:57:27 -0400 Subject: [PATCH] Merge PR #4932: Fix gov query vote cmd --- CHANGELOG.md | 2 ++ x/gov/client/cli/query.go | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d674aa053c..c998894ff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,8 @@ that error is that the account doesn't exist. * (keys) Fix ledger custom coin type support bug * (simulation) [\#4912](https://github.com/cosmos/cosmos-sdk/issues/4912) Fix SimApp ModuleAccountAddrs to properly return black listed addresses for bank keeper initialization * (cli) [\#4919](https://github.com/cosmos/cosmos-sdk/pull/4919) Don't crash cli if user doesn't answer y/n confirmation request +* (cli) [\#4927](https://github.com/cosmos/cosmos-sdk/issues/4927) Fix the `q gov vote` +command to handle empty (pruned) votes correctly. ## [v0.36.0] - 2019-08-13 diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 51d48e7b6d..ad87bceebb 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -215,21 +215,24 @@ $ %s query gov vote 1 cosmos1skjwj5whet0lpe65qaq4rpq03hjxlwd9nf39lk } var vote types.Vote - if err := cdc.UnmarshalJSON(res, &vote); err != nil { - return err - } + + // XXX: Allow the decoding to potentially fail as the vote may have been + // pruned from state. If so, decoding will fail and so we need to check the + // Empty() case. Consider updating Vote JSON decoding to not fail when empty. + _ = cdc.UnmarshalJSON(res, &vote) if vote.Empty() { res, err = gcutils.QueryVoteByTxQuery(cliCtx, params) if err != nil { return err } + if err := cdc.UnmarshalJSON(res, &vote); err != nil { return err } } - return cliCtx.PrintOutput(vote) //nolint:errcheck + return cliCtx.PrintOutput(vote) }, } }