Skip to content

Commit d61baee

Browse files
committed
relevant newsfragments for #3359; update migration guide
1 parent 36c2e2e commit d61baee

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

docs/v7_migration.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,41 @@ keys in the dictionary should be camelCase. This is because the dictionary is pa
189189
directly to the JSON-RPC request, where the keys are expected to be in camelCase.
190190

191191

192+
Changes to Exception Handling
193+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
194+
195+
All Python standard library exceptions that were raised from within *web3.py* have
196+
been replaced with custom ``Web3Exception`` classes. This change allows for better
197+
control over exception handling, being able to distinguish between exceptions raised
198+
by *web3.py* and those raised from elsewhere in a codebase. The following exceptions
199+
have been replaced:
200+
201+
- ``AssertionError`` -> ``Web3AssertionError``
202+
- ``ValueError`` -> ``Web3ValueError``
203+
- ``TypeError`` -> ``Web3TypeError``
204+
- ``AttributeError`` -> ``Web3AttributeError``
205+
206+
A new ``MethodNotSupported`` exception is now raised when a method is not supported by
207+
*web3.py*. This allows a user to distinguish between when a method is not available on
208+
the current provider, ``MethodUnavailable``, and when a method is not supported by
209+
*web3.py* under certain conditions, ``MethodNotSupported``.
210+
211+
212+
JSON-RPC Error Handling
213+
```````````````````````
214+
215+
Rather than a ``ValueError`` being replaced with a ``Web3ValueError`` when a JSON-RPC
216+
response comes back with an ``error`` object, a new ``Web3RPCError`` exception is
217+
now raised to provide more distinction for JSON-RPC error responses. Some previously
218+
existing exceptions now extend from this class since they too are related to JSON-RPC
219+
errors:
220+
221+
- ``MethodUnavailable``
222+
- ``BlockNotFound``
223+
- ``TransactionNotFound``
224+
- ``TransactionIndexingInProgress``
225+
226+
192227
Miscellaneous Changes
193228
~~~~~~~~~~~~~~~~~~~~~
194229

@@ -207,3 +242,5 @@ Miscellaneous Changes
207242
without checking if the ``geth.ipc`` file exists.
208243
- ``Web3.is_address()`` returns ``True`` for non-checksummed addresses.
209244
- ``Contract.encodeABI()`` has been renamed to ``Contract.encode_abi()``.
245+
- JSON-RPC responses are now more strictly validated against the JSON-RPC 2.0
246+
specification while providing more informative error messages for invalid responses.

newsfragments/3359.breaking.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Validate JSON-RPC responses more strictly against the JSON-RPC 2.0 specifications. ``BlockNumberOutofRange`` -> ``BlockNumberOutOfRange``.

newsfragments/3359.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Raise ``Web3RPCError`` on JSON-RPC errors rather than ``Web3ValueError``. Raise ``MethodNotSupported`` exception when a method is not supported within *web3.py*; keep ``MethodUnavailable`` for when a method is not available on the current provider (JSON-RPC error).

0 commit comments

Comments
 (0)