Skip to content

Commit 03095ce

Browse files
feat[ux]: move exception hint to the end of the message (#4154)
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]>
1 parent 5a7b481 commit 03095ce

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

vyper/exceptions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ def hint(self):
9797

9898
@property
9999
def message(self):
100-
msg = self._message
101-
if self.hint:
102-
msg += f"\n\n (hint: {self.hint})"
103-
return msg
100+
return self._message
104101

105102
def format_annotation(self, value):
106103
from vyper import ast as vy_ast
@@ -148,7 +145,16 @@ def format_annotation(self, value):
148145
node_msg = textwrap.indent(node_msg, " ")
149146
return node_msg
150147

148+
def _add_hint(self, msg):
149+
hint = self.hint
150+
if hint is None:
151+
return msg
152+
return msg + f"\n (hint: {self.hint})"
153+
151154
def __str__(self):
155+
return self._add_hint(self._str_helper())
156+
157+
def _str_helper(self):
152158
if not self.annotations:
153159
if self.lineno is not None and self.col_offset is not None:
154160
return f"line {self.lineno}:{self.col_offset} {self.message}"

0 commit comments

Comments
 (0)