-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Unhandled ValueError when calling contract functions #1864
Comments
I'd be happy to put a PR together, but I'd like to hear the developers view on that first. |
Sorry, @ml31415 I lost track of this. I'm for changing ValueError to be something more specific to web3. I think the best option would be to raise something other than |
Thanks for coming back to that! From a user point of view, I'm always a big fan if a library provides a "root" exception, from where all purposefully thrown errors derive, so that I can catch for only that error type, if I'm not sure what exactly might go wrong in some library call. Or to put it in other words: It's great to be able to freely choose the level of granularity when catching an exception. E.g. as seen in class Web3Error(Exception):
pass
# other Web3Error derived errors
# maybe Web3ClientError
class ResponseError(Web3Error): # or Web3ClientError
pass
class ResponseValueError(ValueError, ResponseError):
pass
class ResponseNotFound(KeyError, ResponseError):
# as seen in https://github.com/ethereum/web3.py/blob/125c6aedc618a008f07069f09ddc3430002af0df/web3/manager.py#L197
pass |
Great minds! That is one of the features we're planning on implementing in v6. Tracked in #1478 |
Sorry for having created a duplicate then. Had missed that unfortunately. |
No worries! I think this deserves to be open still since it's a separate request to have a different error come back than |
Hey @kclowes this is still open. We are upgrading rotki's codebase to web3.py v6. After #1839 I thought we would no longer see ValueErrors but I still see them in some places. Example below:
|
🤔 Hmm, yes it is. I think it just got missed in v6. We moved all of our custom exceptions that previously inherited from |
yeah anything common like this so we have clean handling of library exception at all places we use web3, otherwise we end up having to catch both this and ValueError. Thanks! |
Version: master
What was wrong?
Whenever a contract function call fails, for whatever reason, it throws an unspecified
ValueError
, which pops up through all the call stack. For libraries on top it's not possible to properly reason and deal with such an unspecific error. This problem shows up in a lot of issue reports, e.g. #1725 #1717 #651 and nosofa/uniswap-v2-py#10 .How can it be fixed?
To my humble understanding, this should best be handled somewhere in
call_contract_function()
web3.py/web3/contract.py
Line 1470 in d8996bd
web3.py/web3/contract.py
Line 1528 in d8996bd
BadFunctionCallOutput
. Imho the two function calls inweb3.py/web3/contract.py
Line 1497 in d8996bd
BadFunctionCallOutput
or another more specific error.Another and maybe even the better option might be, to replace all the
ValueError
andKeyError
in https://github.com/ethereum/web3.py/blob/master/web3/manager.py with some kind of server side response error right away.The text was updated successfully, but these errors were encountered: