From 03095ce39216362dd4cbff67f8efb2bbb188bb40 Mon Sep 17 00:00:00 2001 From: cyberthirst Date: Mon, 16 Sep 2024 15:47:55 +0200 Subject: [PATCH] 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 --- vyper/exceptions.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vyper/exceptions.py b/vyper/exceptions.py index 3c0444b1ca..c69163b561 100644 --- a/vyper/exceptions.py +++ b/vyper/exceptions.py @@ -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 @@ -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}"