Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rpcclient): avoid losing jsonrpc information upon non-2xx http codes (fix #2422) #2631

Closed
wants to merge 1 commit into from

Conversation

grepsuzette
Copy link
Contributor

@grepsuzette grepsuzette commented Jul 25, 2024

This was an alternative implementation of #2501 to fix #2422.

…codes (fix gnolang#2422)

Regardless of HTTP response code, if jsonrpc was received
we want to unmarshal and use it as the response (gnolang#2422).

Otherwise we get errors such as:

--= Error =--
Data: unable to call RPC method abci_query, invalid status code received, 500
Msg Traces:
    0  /me/gno/tm2/pkg/crypto/keys/client/query.go:94 - querying
--= /Error =--

When a tool like wireshark shows that the following jsonrpc was actually
in the 500 message:

 JSON compact form: {...}
        "jsonrpc": "2.0"
        "id": ""
        "error": {...}
            "code": -32603
            "message": "Internal error"
            "data": "assignment to entry in nil map"

--------------
Discussion:

An easy way to fix gnolang#2422 is to simply append the response body in
case of an HTTP status > 299. But doing so returns an error.
Is this what we want?
---------------------------

The table below indicates what to do based on two bool variables:
 1. is HTTP code 2xx?
 2. can response body be unmarshalled?

/--------+------------------+--------------------------------------\
|        | jsonrpc          | text                                 |
|--------+------------------+--------------------------------------|
| 2xx    | use as response  | Error "unable to unmarshal response" |
| >=300  | use as response⁺ | Error "invalid status code"          |
\------------------------------------------------------------------/
In the case marked with ⁺, we prepend a fmt.Print to show the HTTP
response code to the user.
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.75%. Comparing base (31a5f2e) to head (b3486b2).
Report is 94 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2631      +/-   ##
==========================================
+ Coverage   54.70%   54.75%   +0.05%     
==========================================
  Files         582      584       +2     
  Lines       78430    78490      +60     
==========================================
+ Hits        42902    42976      +74     
+ Misses      32315    32289      -26     
- Partials     3213     3225      +12     
Flag Coverage Δ
misc/autocounterd 0.00% <ø> (ø)
misc/genstd 80.54% <ø> (+6.64%) ⬆️
misc/goscan 0.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

gnokey does not show the full HTTP response in case of error
1 participant