Cosmos-sdk: /gov/proposals/<proposalID>/votes/<voterAddr> returns HTTP 500 on vote doesn't exist

Created on 31 Dec 2018  路  11Comments  路  Source: cosmos/cosmos-sdk

Summary of Bug

When calling the LCD endpoint /gov/proposals/<proposalID>/votes/<voterAddr>, HTTP 404 should be the response when the use has not voted, however this returns a 500 response in 0.29.0.

curl -v -k https://localhost:1317/gov/proposals/1/votes/cosmos1a0g3j2y3mlg9eh7tjm7zh2jazxk3qwzkglevhp
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 1317 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: O=Gaia Lite
*  start date: Dec 30 19:55:57 2018 GMT
*  expire date: Jan 29 19:55:57 2019 GMT
*  issuer: O=Gaia Lite
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x5555557bc8e0)
> GET /gov/proposals/1/votes/cosmos1a0g3j2y3mlg9eh7tjm7zh2jazxk3qwzkglevhp HTTP/2
> Host: localhost:1317
> User-Agent: curl/7.58.0
> Accept: */*
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 500
< x-server-time: 1546278527
< content-type: text/plain; charset=utf-8
< content-length: 84
< date: Mon, 31 Dec 2018 17:48:47 GMT
<
* Connection #0 to host localhost left intact
address 'cosmos1a0g3j2y3mlg9eh7tjm7zh2jazxk3qwzkglevhp' did not vote on proposalID 1

For Admin Use

  • [ ] Not duplicate issue
  • [ ] Appropriate labels applied
  • [ ] Appropriate contributors tagged
  • [ ] Contributor assigned/self-assigned
Legacy API bug good first issue stale

All 11 comments

I don't recall if this is a convention API wide, but shouldn't the response be json anyway?

Indeed, since QueryVoteByTxQuery simply returns an error, we don't really know if we should return a 500 or 404 or another status code. Perhaps we can think of a more flexible way to handle this (e.g. return a typed error and switch on that).

But as you suggested, at the very least, it should return a JSON response 馃憤

res, err = gcutils.QueryVoteByTxQuery(cdc, cliCtx, params)
if err != nil {
    utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
    return
}

It looks like the whole governance module has this issue. It looks like the easiest way to solve this is to add a error type:

type NotFoundError struct { Message string }
func (nf NotFoundError) Error() string { return nf.Message }
func NewNotFoundError(m string) { return NotFoundError{Message: m} }

And then return this if the tx.SearchTxs calls fail to find any transactions. The other errors returned by the initial function would be from JSON marshaling. We can return 500s for those.

This improved but still the behaviour is not what expected.

{"error":"'' is not a valid vote option"}

I can't reproduce that @sabau:

example:
http://134.209.33.64:1317/gov/proposals/5/votes/cosmos1qwl879nx9t6kef4supyazayf7vjhennyjqwjgr

Weird, I see this also on the link you posted:

https://youtu.be/fNsjNy_ebNI

wait, now I get that error too. Seems it's a bug indeed.

Is this still an issue @sabau

I just tested to see if it is fixed, and this seems to be an ongoing issue.

Welcoming a community contribution here :)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings