1010)
1111
1212
13- class BadFunctionCallOutput (Exception ):
13+ class Web3Exception (Exception ):
14+ """
15+ Exception mixin inherited by all exceptions of web3.py
16+
17+ This allows::
18+
19+ try:
20+ some_call()
21+ except Web3Exception:
22+ # deal with web3 exception
23+ except:
24+ # deal with other exceptions
25+ """
26+
27+
28+ class BadFunctionCallOutput (Web3Exception ):
1429 """
1530 We failed to decode ABI output.
1631
@@ -20,15 +35,15 @@ class BadFunctionCallOutput(Exception):
2035 pass
2136
2237
23- class BlockNumberOutofRange (Exception ):
38+ class BlockNumberOutofRange (Web3Exception ):
2439 """
2540 block_identifier passed does not match known block.
2641 """
2742
2843 pass
2944
3045
31- class CannotHandleRequest (Exception ):
46+ class CannotHandleRequest (Web3Exception ):
3247 """
3348 Raised by a provider to signal that it cannot handle an RPC request and
3449 that the manager should proceed to the next provider.
@@ -37,15 +52,15 @@ class CannotHandleRequest(Exception):
3752 pass
3853
3954
40- class TooManyRequests (Exception ):
55+ class TooManyRequests (Web3Exception ):
4156 """
4257 Raised by a provider to signal that too many requests have been made consecutively.
4358 """
4459
4560 pass
4661
4762
48- class MultipleFailedRequests (Exception ):
63+ class MultipleFailedRequests (Web3Exception ):
4964 """
5065 Raised by a provider to signal that multiple requests to retrieve the same
5166 (or similar) data have failed.
@@ -54,15 +69,15 @@ class MultipleFailedRequests(Exception):
5469 pass
5570
5671
57- class InvalidAddress (ValueError ):
72+ class InvalidAddress (Web3Exception ):
5873 """
5974 The supplied address does not have a valid checksum, as defined in EIP-55
6075 """
6176
6277 pass
6378
6479
65- class NameNotFound (ValueError ):
80+ class NameNotFound (Web3Exception ):
6681 """
6782 Raised when a caller provides an Ethereum Name Service name that
6883 does not resolve to an address.
@@ -71,7 +86,7 @@ class NameNotFound(ValueError):
7186 pass
7287
7388
74- class StaleBlockchain (Exception ):
89+ class StaleBlockchain (Web3Exception ):
7590 """
7691 Raised by the stalecheck_middleware when the latest block is too old.
7792 """
@@ -93,7 +108,7 @@ def __str__(self) -> str:
93108 return self .args [0 ]
94109
95110
96- class MismatchedABI (Exception ):
111+ class MismatchedABI (Web3Exception ):
97112 """
98113 Raised when an ABI does not match with supplied parameters, or when an
99114 attempt is made to access a function/event that does not exist in the ABI.
@@ -120,15 +135,15 @@ class ABIFunctionNotFound(AttributeError, MismatchedABI):
120135 pass
121136
122137
123- class FallbackNotFound (Exception ):
138+ class FallbackNotFound (Web3Exception ):
124139 """
125140 Raised when fallback function doesn't exist in contract.
126141 """
127142
128143 pass
129144
130145
131- class ValidationError (Exception ):
146+ class ValidationError (Web3Exception ):
132147 """
133148 Raised when a supplied value is invalid.
134149 """
@@ -144,31 +159,31 @@ class ExtraDataLengthError(ValidationError):
144159 pass
145160
146161
147- class NoABIFunctionsFound (AttributeError ):
162+ class NoABIFunctionsFound (Web3Exception ):
148163 """
149164 Raised when an ABI is present, but doesn't contain any functions.
150165 """
151166
152167 pass
153168
154169
155- class NoABIFound (AttributeError ):
170+ class NoABIFound (Web3Exception ):
156171 """
157172 Raised when no ABI is present.
158173 """
159174
160175 pass
161176
162177
163- class NoABIEventsFound (AttributeError ):
178+ class NoABIEventsFound (Web3Exception ):
164179 """
165180 Raised when an ABI doesn't contain any events.
166181 """
167182
168183 pass
169184
170185
171- class InsufficientData (Exception ):
186+ class InsufficientData (Web3Exception ):
172187 """
173188 Raised when there are insufficient data points to
174189 complete a calculation
@@ -177,7 +192,7 @@ class InsufficientData(Exception):
177192 pass
178193
179194
180- class TimeExhausted (Exception ):
195+ class TimeExhausted (Web3Exception ):
181196 """
182197 Raised when a method has not retrieved the desired
183198 result within a specified timeout.
@@ -186,7 +201,7 @@ class TimeExhausted(Exception):
186201 pass
187202
188203
189- class PMError (Exception ):
204+ class PMError (Web3Exception ):
190205 """
191206 Raised when an error occurs in the PM module.
192207 """
@@ -202,48 +217,47 @@ class ManifestValidationError(PMError):
202217 pass
203218
204219
205- class TransactionNotFound (Exception ):
220+ class TransactionNotFound (Web3Exception ):
206221 """
207222 Raised when a tx hash used to lookup a tx in a jsonrpc call cannot be found.
208223 """
209224
210225 pass
211226
212227
213- class BlockNotFound (Exception ):
228+ class BlockNotFound (Web3Exception ):
214229 """
215230 Raised when the block id used to lookup a block in a jsonrpc call cannot be found.
216231 """
217232
218233 pass
219234
220235
221- class InfuraProjectIdNotFound (Exception ):
236+ class InfuraProjectIdNotFound (Web3Exception ):
222237 """
223238 Raised when there is no Infura Project Id set.
224239 """
225240
226241 pass
227242
228243
229- class LogTopicError (ValueError ):
230- # Inherits from ValueError for backwards compatibility
244+ class LogTopicError (Web3Exception ):
231245 """
232246 Raised when the number of log topics is mismatched.
233247 """
248+
234249 pass
235250
236251
237- class InvalidEventABI (ValueError ):
238- # Inherits from ValueError for backwards compatibility
252+ class InvalidEventABI (Web3Exception ):
239253 """
240254 Raised when the event ABI is invalid.
241255 """
256+
242257 pass
243258
244259
245- class ContractLogicError (ValueError ):
246- # Inherits from ValueError for backwards compatibility
260+ class ContractLogicError (Web3Exception ):
247261 """
248262 Raised on a contract revert error
249263 """
@@ -259,7 +273,7 @@ def __init__(self, payload: Dict[str, Any]) -> None:
259273 super ().__init__ ()
260274
261275
262- class InvalidTransaction (Exception ):
276+ class InvalidTransaction (Web3Exception ):
263277 """
264278 Raised when a transaction includes an invalid combination of arguments.
265279 """
@@ -279,9 +293,9 @@ def __init__(self) -> None:
279293 super ().__init__ (message )
280294
281295
282- class BadResponseFormat (ValueError , KeyError ):
283- # Inherits from KeyError and ValueError for backwards compatibility
296+ class BadResponseFormat (Web3Exception ):
284297 """
285298 Raised when a JSON-RPC response comes back in an unexpected format
286299 """
300+
287301 pass
0 commit comments