Skip to content

fix[tool]: add missing user errors to error map #4286

Merged
charles-cooper merged 21 commits intovyperlang:masterfrom
sandbubbles:fix/user_error_not_in_error_map
Dec 13, 2024
Merged

fix[tool]: add missing user errors to error map #4286
charles-cooper merged 21 commits intovyperlang:masterfrom
sandbubbles:fix/user_error_not_in_error_map

Conversation

@sandbubbles
Copy link
Copy Markdown
Contributor

@sandbubbles sandbubbles commented Oct 11, 2024

What I did

Fix #4199

How I did it

Moved error message to "revert"

How to verify it

Commit message

This commit fixes a bug where not all errors are present in the
error_map (in the `-f source_map` output). This could happen when the
`IRnode` with an error message was optimized out, since the error
message was not propagated to its descendants.

To resolve this, two changes were made. In `set_error_msg`, the code
now ensures that existing error messages are not overwritten if they
have already been set. In `IRnode.from_list`, when an `error_msg`
argument is provided, it is assigned to all nodes in the list unless a
node already has an existing `error_msg`. Both changes were made, since
both methods are used in the codebase to set `IRnode.error_msg`.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Edit: commit msg

raise "some error"
"""
error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
assert "user revert with reason" in list(error_map.values())
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 45.57%. Comparing base (e0fc53a) to head (5f2cd05).
Report is 9 commits behind head on master.

❗ There is a different number of reports uploaded between BASE (e0fc53a) and HEAD (5f2cd05). Click for more details.

HEAD has 136 uploads less than BASE
Flag BASE (e0fc53a) HEAD (5f2cd05)
137 1
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #4286       +/-   ##
===========================================
- Coverage   91.27%   45.57%   -45.71%     
===========================================
  Files         112      112               
  Lines       16017    16017               
  Branches     2696     2696               
===========================================
- Hits        14619     7299     -7320     
- Misses        966     8159     +7193     
- Partials      432      559      +127     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

As discussed offline- please check if it is feasible to call set_error_msg in the from_list factory

passthrough_metadata=passthrough_metadata,
)
if error_msg is not None:
ret.set_error_msg(error_msg)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe _set_error_msg, since the IRnode may already have error_msg set

@cyberthirst
Copy link
Copy Markdown
Collaborator

i think the PR addresses the issue

but we're still overriding error messages for less concrete ones in set_error_msg

following will fail

def test_error_map_with_user_error2():
    code = """
@external
def foo(i: uint256):
    a: DynArray[uint256, 10] = [1]
    a[i % 10] = 2
    """
    error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
    assert "safemod" in error_map.values()

as it will get overwritten by

 ix.set_error_msg(f"{parent.typ} bounds check")

@charles-cooper
Copy link
Copy Markdown
Member

i think the PR addresses the issue

but we're still overriding error messages for less concrete ones in set_error_msg

following will fail

def test_error_map_with_user_error2():
    code = """
@external
def foo(i: uint256):
    a: DynArray[uint256, 10] = [1]
    a[i % 10] = 2
    """
    error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
    assert "safemod" in error_map.values()

as it will get overwritten by

 ix.set_error_msg(f"{parent.typ} bounds check")

this is a good catch. @sandbubbles can you add the guard to set_error_msg() as you had before so it blocks the recursion if error msg is already set?

@cyberthirst cyberthirst added the release - must release blocker label Dec 11, 2024
@sandbubbles
Copy link
Copy Markdown
Contributor Author

i think the PR addresses the issue
but we're still overriding error messages for less concrete ones in set_error_msg
following will fail

def test_error_map_with_user_error2():
    code = """
@external
def foo(i: uint256):
    a: DynArray[uint256, 10] = [1]
    a[i % 10] = 2
    """
    error_map = compile_code(code, output_formats=["source_map"])["source_map"]["error_map"]
    assert "safemod" in error_map.values()

as it will get overwritten by

 ix.set_error_msg(f"{parent.typ} bounds check")

this is a good catch. @sandbubbles can you add the guard to set_error_msg() as you had before so it blocks the recursion if error msg is already set?

Done:), should be ready for another check.

@charles-cooper charles-cooper changed the title fix[lang]: show user error in error map fix[tool]: show user error in error map Dec 11, 2024
@charles-cooper charles-cooper changed the title fix[tool]: show user error in error map fix[tool]: add missing user errors to error map Dec 11, 2024
Copy link
Copy Markdown
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

lgtm

@charles-cooper
Copy link
Copy Markdown
Member

@sandbubbles please write out a commit message for this pull request :)

@charles-cooper charles-cooper requested review from cyberthirst and removed request for cyberthirst December 11, 2024 23:47
@charles-cooper charles-cooper merged commit c4669d1 into vyperlang:master Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release - must release blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

user errors not appearing in error map

3 participants