Cosmos-sdk: APIs missing error when querying using invalid proposalId

Created on 11 Dec 2018  Â·  5Comments  Â·  Source: cosmos/cosmos-sdk

Summary of Bug


I tried to query the SDK using a non existent proposalId, and the reply was null instead of the proper error body with message.

Steps to Reproduce

  • get null as reply

For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
UX bug needs-more-info

All 5 comments

gaiacli works as expected:

alessio@bangalter:~/.../cosmos/cosmos-sdk$ gaiacli query gov votes --chain-id=test-chain-P0ajzL 3
ERROR: Failed to fetch proposal-id 3: {"codespace":"GOV","code":1,"message":"Unknown proposal with id 3"}

I guess the REST endpoint needs some love here.

Reproduced via test case:

diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go
index 164edb0f..82367e89 100644
--- a/client/lcd/lcd_test.go
+++ b/client/lcd/lcd_test.go
@@ -740,4 +740,8 @@ func TestProposalsQuery(t *testing.T) {
        require.Len(t, votes, 2)
        require.True(t, addrs[0].String() == votes[0].Voter.String() || addrs[0].String() == votes[1].Voter.String())
        require.True(t, addrs[1].String() == votes[0].Voter.String() || addrs[1].String() == votes[1].Voter.String())
+
+       // Test query votes on non-existent proposal
+       votes = getVotes(t, port, 99)
+       require.Len(t, votes, 0)
 }

The test pass, no error is returned. CC'ing who touched the code last: @sunnya97
Was return no error a design choice? I'd be inclined to think that 0 votes should be returned if the proposal exists but got no votes, whilst an error should be returned if there's no such proposal at all. Thoughts?

I think this overlaps with #3091. In that PR, I now return an error IF the proposal is inactive (votes/deposits removed from state). BUT, if the proposal is still active and there are no votes/deposits, it still returns null.

This should be fixed in https://github.com/cosmos/cosmos-sdk/commit/ff6c2f2badd4784b48a7552dfb44fbf3bae5418d.
@sabau Would you mind to try reproduce the issue with latest develop please?

Work nicely now

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rigelrozanski picture rigelrozanski  Â·  3Comments

ValarDragon picture ValarDragon  Â·  3Comments

kevlubkcm picture kevlubkcm  Â·  3Comments

hendrikhofstadt picture hendrikhofstadt  Â·  3Comments

mossid picture mossid  Â·  3Comments