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

fix[lang]: show user error in error map #4286

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions tests/unit/compiler/test_source_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ def update_foo():
assert "fallback function" in list(error_map.values())


def test_error_map_with_user_error():
code = """
@external
def foo():
raise "some error"
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
assert "user revert with reason" in list(error_map.values())
Copy link
Collaborator

Choose a reason for hiding this comment

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

why can't we check in error_map.values()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can. test_error_map also wraps the values in list - should I change it there too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a dict view, i think we should. @charles-cooper do you remember the reason you did it this way?

Copy link
Member

Choose a reason for hiding this comment

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

it's a dict view, i think we should. @charles-cooper do you remember the reason you did it this way?

no, just habit i think


def test_compress_source_map():
# mock the required VyperNode fields in compress_source_map
# fake_node = namedtuple("fake_node", ("lineno", "col_offset", "end_lineno", "end_col_offset"))
Expand Down
5 changes: 3 additions & 2 deletions vyper/codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,16 @@ def _assert_reason(self, test_expr, msg):
revert_seq = [
"seq",
["mstore", buf, method_id],
["revert", add_ofst(buf, 28), ["add", 4, encoded_length]],
]
revert = ["revert", add_ofst(buf, 28), ["add", 4, encoded_length]]
revert_seq.append(IRnode.from_list(revert, error_msg="user revert with reason"))
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
revert_seq = b1.resolve(revert_seq)

if is_raise:
ir_node = revert_seq
else:
ir_node = ["if", ["iszero", test_expr], revert_seq]
return IRnode.from_list(ir_node, error_msg="user revert with reason")
return IRnode.from_list(ir_node)

def parse_Assert(self):
test_expr = Expr.parse_value_expr(self.stmt.test, self.context)
Expand Down