Skip to content
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

chore: improve error message for undeclared enum member #3264

Merged
merged 3 commits into from
Jan 31, 2023

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented Jan 30, 2023

What I did

Fix #3262

How I did it

Set EnumT._helper._id to the same name as the EnumT.

How to verify it

See test.

Commit message

chore: improve error message for undeclared enum member

Description for the changelog

Improve error message for undeclared enum member

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2023

Codecov Report

Merging #3264 (e570464) into master (02339df) will decrease coverage by 0.29%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #3264      +/-   ##
==========================================
- Coverage   88.88%   88.60%   -0.29%     
==========================================
  Files          84       84              
  Lines       10598    10599       +1     
  Branches     2212     2212              
==========================================
- Hits         9420     9391      -29     
- Misses        769      796      +27     
- Partials      409      412       +3     
Impacted Files Coverage Δ
vyper/semantics/types/user.py 85.62% <100.00%> (+0.04%) ⬆️
vyper/codegen/arithmetic.py 79.61% <0.00%> (-5.10%) ⬇️
vyper/builtins/functions.py 88.63% <0.00%> (-1.80%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tserg tserg marked this pull request as ready for review January 30, 2023 10:35
@@ -55,6 +55,9 @@ def __init__(self, name: str, members: dict) -> None:
# also conveniently checks well-formedness of the members namespace
self._helper = VyperType(members)

# set the name for exception handling in `get_member`
self._helper._id = name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit funky, basically a side effect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so that it can be handled by L300 here:

def get_member(self, key: str, node: vy_ast.VyperNode) -> "VyperType":
if key in self.members:
return self.members[key]
# special error message for types with no members
if not self.members:
raise StructureException(f"{self} instance does not have members", node)
suggestions_str = get_levenshtein_error_suggestions(key, self.members, 0.3)
raise UnknownAttribute(f"{self} has no member '{key}'. {suggestions_str}", node)
def __repr__(self):
return self._id

@charles-cooper charles-cooper merged commit a0d2541 into vyperlang:master Jan 31, 2023
@tserg tserg deleted the fix/enum_exception branch January 31, 2023 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error message for missing enum item
4 participants