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

feat[ux]: move exception hint to the end of the message #4154

Merged
merged 10 commits into from
Sep 16, 2024
38 changes: 24 additions & 14 deletions vyper/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,33 @@ def hint(self):
return self._hint()
return self._hint

@property
def annotation_message(self):
cyberthirst marked this conversation as resolved.
Show resolved Hide resolved
msg = self._message
assert self.annotations is not None
annotation_list = []

if self.prev_decl is not None:
formatted_decl = self.format_annotation(self.prev_decl)
formatted_decl = f" (previously declared at):\n{formatted_decl}"
annotation_list.append(formatted_decl)

for value in self.annotations:
annotation_list.append(self.format_annotation(value))

annotation_list = [s for s in annotation_list if s is not None]
annotation_msg = "\n".join(annotation_list)
msg += f"\n\n{annotation_msg}"
if self.hint:
msg += f"\n (hint: {self.hint})"

return msg

@property
def message(self):
msg = self._message
if self.hint:
msg += f"\n\n (hint: {self.hint})"
msg += f"\n (hint: {self.hint})"
return msg

def format_annotation(self, value):
Expand Down Expand Up @@ -155,19 +177,7 @@ def __str__(self):
else:
return self.message

annotation_list = []

if self.prev_decl is not None:
formatted_decl = self.format_annotation(self.prev_decl)
formatted_decl = f" (previously declared at):\n{formatted_decl}"
annotation_list.append(formatted_decl)

for value in self.annotations:
annotation_list.append(self.format_annotation(value))

annotation_list = [s for s in annotation_list if s is not None]
annotation_msg = "\n".join(annotation_list)
return f"{self.message}\n\n{annotation_msg}"
return self.annotation_message


class VyperException(_BaseVyperException):
Expand Down
Loading