Skip to content

Commit

Permalink
feat[ux]: move exception hint to the end of the message (vyperlang#4154)
Browse files Browse the repository at this point in the history
moved the `(hint: ...)` to be reported at the end of the exception to
improve the readability. the hint should be displayed after the actual
problem has been described, i.e. as the last item in the exception
message.

---------

Co-authored-by: Charles Cooper <[email protected]>
  • Loading branch information
cyberthirst and charles-cooper authored Sep 16, 2024
1 parent 5a7b481 commit 03095ce
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions vyper/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ def hint(self):

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

def format_annotation(self, value):
from vyper import ast as vy_ast
Expand Down Expand Up @@ -148,7 +145,16 @@ def format_annotation(self, value):
node_msg = textwrap.indent(node_msg, " ")
return node_msg

def _add_hint(self, msg):
hint = self.hint
if hint is None:
return msg
return msg + f"\n (hint: {self.hint})"

def __str__(self):
return self._add_hint(self._str_helper())

def _str_helper(self):
if not self.annotations:
if self.lineno is not None and self.col_offset is not None:
return f"line {self.lineno}:{self.col_offset} {self.message}"
Expand Down

0 comments on commit 03095ce

Please sign in to comment.