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 12 commits into
base: master
Choose a base branch
from
14 changes: 12 additions & 2 deletions tests/unit/compiler/test_source_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,18 @@ def update_foo():
self.foo += 1
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
assert "safeadd" in list(error_map.values())
assert "fallback function" in list(error_map.values())
assert "safeadd" in error_map.values()
assert "fallback function" in 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 error_map.values()


def test_compress_source_map():
Expand Down
5 changes: 4 additions & 1 deletion vyper/codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@
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")

ir_node = IRnode.from_list(ir_node)
ir_node.set_error_msg("user revert with reason")
Copy link
Collaborator

Choose a reason for hiding this comment

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

what if some of the arguments have their own error message? Then it gets overwritten although it might be more specific.

eg in the case of raise self.bar(5 % i) the mod is annotated with a safemod error msg, which will be replaced with user revert with reason

Copy link
Member

Choose a reason for hiding this comment

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

Hmm I did implement set_error_msg to override, but that could be changed. @sandbubbles could you change that in this PR to not override? And add @cyberthirst's test case raise self.foo(5%i) to the test suite.

return ir_node

Check warning on line 161 in vyper/codegen/stmt.py

View check run for this annotation

Codecov / codecov/patch

vyper/codegen/stmt.py#L159-L161

Added lines #L159 - L161 were not covered by tests

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