-
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
Improve error messages on mismatched argument types #964
Comments
Is there any official documentation, about how to provide the values for several types? It could help to add some documentation in the Web3 libraries (JS, Python, ...) to provide examples on how to encode specific Ethereum types in these languages/libraries. |
There is some documentation here about different types, but it's not very comprehensive, and could certainly stand to be improved. What types would you like to see documentation on @MatthiasLohr? |
Oh, that would have been good to have had this link yesterday. ;) So first: It seems to be somehow hard to find. I have seen this point "Conventions", but didn't take a deep look into it because it somehow felt far away from my problem. Yesterday I tried to call a contract with web3py with error (something like) "found (str, bytes[]), need (address, bytes32). For me, at first place, it looked like a a working mapping, because the str object was a (checksum) address hex string and bytes[] was 32 bytes long (actually, it was not, that was the actual problem).
If there are multiple possibilities for the mapping, all variants should be listed. I'm not that into Solidity/Web3Py so that I don't know all mappings. But maybe my idea is clear and helps to improve the documentation. |
Ah, dang! That's the worst.
Yep, agreed. Maybe a rename to "Type Conventions" or even "Special Type Conventions" would be clearer? Open to other options though if you think of something better.
I like this idea! I'm doing something similar in #1419 here for bytes types, but probably addresses and ints also deserve to have their own sections. And the error message can definitely stand to be improved as well. Thanks for the comments @MatthiasLohr! |
Why not just "Types"? Conventions can be so much more (Coding Conventions, if you want to start to contribute, Naming Conventions for internal variables, ...). Just "Types" reflects, what the page currently contains. |
Perhaps "ABI Types" (or "ABI Type Conversion")? I think it's specific and comprehensive enough to say we are talking about how to convert python native types to the ABI-encoded types, and back. |
Sounds good. Would also be good to have a link in Smart Contract calling examples (how to convert your Python datatypes to Solidity types, see (e.g.) "ABI Type Conversion"). |
Anything new on this? Any chance on getting some more verbose on information what actually went wrong on type conversion when executing code? |
We'd be happy to review and provide feedback on a pull request if you'd like to take a stab at it. |
The problem is: If I would know how to debug/find out what exactly the problem is, I wouldn't have to write here and ask for more details ;) |
Here are the two entry points where I expect this functionality would be easiest to add: web3.py/web3/_utils/contracts.py Lines 75 to 161 in 6258d2e
In the case of To further improve the messages, we'll need to do a bit deeper adjustment of the code upon failure to find a match to gather the following data: For each ABI definition, determine whether it matches each individual criteria (name,number-of-args,argument-types) and then format that data into a single error message detailing each of the function's, their function signatures, and whether they matched the required critera. (Just dumping this here so that when this does get worked on, it's a bit easier to figure out where to start and what needs to be done) |
What was wrong?
When sending an argument with the wrong type to a contract function, people find it difficult to debug and end up frustrated, like in #625
How can it be fixed?
We largely solve for the general case: that multiple functions can exist with the same name. Obviously we have to support that, but it's incredibly common to have names that are unique even without the argument types. In these cases, we can give clearer error messages about exactly which types are expected for which arguments.
For example, we could raise the function:
The text was updated successfully, but these errors were encountered: