File tree Expand file tree Collapse file tree 5 files changed +46
-0
lines changed Expand file tree Collapse file tree 5 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,9 @@ Other Misc Changes
92
92
93
93
- ``InfuraKeyNotFound `` exception has been changed to ``InfuraProjectIdNotFound ``
94
94
- ``SolidityError `` has been removed in favor of ``ContractLogicError ``
95
+ - When a method is unavailable from a node provider (i.e. a response error
96
+ code of -32601 is returned), a ``MethodUnavailable `` error is
97
+ now raised instead of ``ValueError ``
95
98
96
99
Removals
97
100
~~~~~~~~
Original file line number Diff line number Diff line change
1
+ When a method is not supported by a node provider, raise a MethodUnavailable error instead of the generic ValueError.
Original file line number Diff line number Diff line change 13
13
BadResponseFormat ,
14
14
BlockNotFound ,
15
15
ContractLogicError ,
16
+ MethodUnavailable ,
16
17
TransactionNotFound ,
17
18
)
18
19
32
33
"message" : "You cannot query logs for more than 10000 blocks at once." ,
33
34
"method" : "eth_getLogs" ,
34
35
}
36
+ METHOD_NOT_FOUND_RESP_FORMAT = {
37
+ "jsonrpc" : "2.0" ,
38
+ "error" : {
39
+ "code" : - 32601 ,
40
+ "message" : "the method eth_getTransactionByHash does not exist/is not "
41
+ "available" ,
42
+ },
43
+ }
44
+ ETH_TESTER_METHOD_NOT_FOUND_RESP_FORMAT = {
45
+ "error" : "the method eth_getTransactionByHash does not exist/is not available" ,
46
+ }
35
47
36
48
37
49
def raise_contract_logic_error (response ):
@@ -105,6 +117,20 @@ def raise_contract_logic_error(response):
105
117
raise_transaction_not_found ,
106
118
TransactionNotFound ,
107
119
),
120
+ (
121
+ METHOD_NOT_FOUND_RESP_FORMAT ,
122
+ (),
123
+ identity ,
124
+ identity ,
125
+ MethodUnavailable ,
126
+ ),
127
+ (
128
+ ETH_TESTER_METHOD_NOT_FOUND_RESP_FORMAT ,
129
+ (),
130
+ identity ,
131
+ identity ,
132
+ ValueError ,
133
+ ),
108
134
],
109
135
)
110
136
def test_formatted_response_raises_errors (
Original file line number Diff line number Diff line change @@ -287,3 +287,11 @@ class BadResponseFormat(Web3Exception):
287
287
"""
288
288
289
289
pass
290
+
291
+
292
+ class MethodUnavailable (Web3Exception ):
293
+ """
294
+ Raised when the method is not available on the node
295
+ """
296
+
297
+ pass
Original file line number Diff line number Diff line change 34
34
)
35
35
from web3 .exceptions import (
36
36
BadResponseFormat ,
37
+ MethodUnavailable ,
37
38
)
38
39
from web3 .middleware import (
39
40
abi_middleware ,
@@ -188,6 +189,13 @@ def formatted_response(
188
189
) -> Any :
189
190
if "error" in response :
190
191
apply_error_formatters (error_formatters , response )
192
+
193
+ # guard against eth-tester case - eth-tester returns a string
194
+ # with no code, so can't parse what the error is.
195
+ if isinstance (response ["error" ], dict ):
196
+ resp_code = response ["error" ].get ("code" )
197
+ if resp_code == - 32601 :
198
+ raise MethodUnavailable (response ["error" ])
191
199
raise ValueError (response ["error" ])
192
200
# NULL_RESPONSES includes None, so return False here as the default
193
201
# so we don't apply the null_result_formatters if there is no 'result' key
You can’t perform that action at this time.
0 commit comments