fix[ux]: fix error message for common typo#4363
fix[ux]: fix error message for common typo#4363charles-cooper wants to merge 4 commits intovyperlang:masterfrom
Conversation
the `staticall` typo is very common, and was raising a hard-to-read error message from the python parser like "invalid syntax. Perhaps you forgot a comma?" this commit adds it to the pre-parser, so we can raise an exception after we have successfully gone through the python parser and have the ability to add source info and a hint.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4363 +/- ##
==========================================
- Coverage 91.23% 90.46% -0.78%
==========================================
Files 112 112
Lines 16010 16012 +2
Branches 2697 2698 +1
==========================================
- Hits 14607 14485 -122
- Misses 968 1072 +104
- Partials 435 455 +20 ☔ View full report in Codecov by Sentry. |
| compile_code(bad_code) | ||
|
|
||
|
|
||
| def test_bad_staticcall_keyword(): |
There was a problem hiding this comment.
The test contract itself is incomplete. Can we make sure we unit test only the introduced change here?
A correct (i.e. compileable) Vyper contract would look like this
from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed
@external
def foo():
extcall IERC20(msg.sender).transfer(
msg.sender,
convert(staticcall IERC20Detailed(msg.sender).decimals(), uint256),
)so we could have the following here:
from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed
@external
def foo():
extcall IERC20(msg.sender).transfer(
msg.sender,
convert(staticall IERC20Detailed(msg.sender).decimals(), uint256),
)Another example with nested staticcall could be:
from ethereum.ercs import IERC20
from ethereum.ercs import IERC20Detailed
@view
def bar() -> uint256:
return staticcall IERC20(msg.sender).balanceOf(
convert(staticall IERC20Detailed(msg.sender).decimals(), address)
)In the last example, if you replace view with pure, it will raise the staticcall first instead of:
vyper.exceptions.StateAccessViolation: Cannot call a view function from a pure functionwhich is the expected behaviour IMO.
| CUSTOM_EXPRESSION_TYPES = { | ||
| "extcall": "ExtCall", | ||
| "staticcall": "StaticCall", | ||
| "staticall": "BadStaticCall", # common typo - we parse it to AST for better error reporting |
There was a problem hiding this comment.
some other (not so common, but still) typos are:
staticcal(that one we should probably also cover)statiiccallstacticallstaticcal
There was a problem hiding this comment.
although I can imagine such mistakes being made, I don't like the idea that we would reserve 5 keywords just for error reporting (though I don't think such keywords would be used by users anyway)
|
very unlikely.. but for completness staticall: uint256or def staticall():
pass
yieds same the same ex edit: added examples |
|
@cyberthirst raised offline -- could we preprocess the error message to look for the typo instead of reserving a keyword? |
staticall typo
staticall typo|
closing in favor of #4438 |
the
staticalltypo is very common, and was raising a hard-to-read error message from the python parser like "invalid syntax. Perhaps you forgot a comma?"this commit adds it to the pre-parser, so we can raise an exception after we have successfully gone through the python parser and have the ability to add source info and a hint.
What I did
How I did it
How to verify it
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture