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[ux]: syntax exception missing filename #4343

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

sandbubbles
Copy link
Collaborator

What I did

Print filename for syntax exceptions as in #4285.

How I did it

Rethrow syntax exceptions from a point where path is known (two places - one for natspec, one for the rest).

How to verify it

Commit message

Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)

Description for the changelog

Cute Animal Picture

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

Copy link

codecov bot commented Nov 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.48%. Comparing base (c32b9b4) to head (1b0e02a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4343      +/-   ##
==========================================
- Coverage   91.23%   88.48%   -2.76%     
==========================================
  Files         112      112              
  Lines       16010    16026      +16     
  Branches     2697     2698       +1     
==========================================
- Hits        14607    14180     -427     
- Misses        968     1322     +354     
- Partials      435      524      +89     

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


🚨 Try these New Features:

@@ -134,6 +135,9 @@ def format_annotation(self, value):
if fn_node:
node_msg = f'{node_msg}function "{fn_node.name}", '

if self.path is not None:
node_msg = f'{node_msg}contract "{self.path}", '
Copy link
Member

Choose a reason for hiding this comment

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

code smell that this code is similar with line 132 above -- and in fact, line 132 appends lineno but this does not. also the path could be appended twice in case there is both a node and .path set on this exception

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is it better now?

sandbubbles and others added 5 commits November 7, 2024 11:43
…4337)

Make "venom" an alternative alias to the "experimental_codegen" flag.
Add the alias to cli, pre-parser, and json parser.
the call to `setup()` would fail on windows when there are unicode
characters in `README.md`, because files are apparently opened with
encoding `cp1252` by default on windows. this commit ensures the file
is opened with `utf-8` encoding.
@sandbubbles sandbubbles marked this pull request as ready for review November 9, 2024 10:21
@@ -151,6 +155,9 @@ def _add_hint(self, msg):
return msg
return msg + f"\n (hint: {self.hint})"

def _append_contract(self, msg, path, lineno):
Copy link
Member

Choose a reason for hiding this comment

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

_append_contract() sounds like it modifies the Exception, but this is a helper function.

@@ -174,7 +175,11 @@ def resolved_imports(self):
def _annotate(self) -> tuple[natspec.NatspecOutput, vy_ast.Module]:
module = self._resolve_imports[0]
analyze_module(module)
nspec = natspec.parse_natspec(module)
try:
nspec = natspec.parse_natspec(module)
Copy link
Member

Choose a reason for hiding this comment

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

i just checked natspec.py and don't see that it throws SyntaxException anywhere?

Copy link
Member

Choose a reason for hiding this comment

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

nvm -- NatspecSyntaxException inherits from SyntaxException. however it will be better to have the try/catch in parse_natspec itself (in case it's ever used from somewhere else)

Copy link
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.

left some comments

vyper/ast/natspec.py Fixed Show fixed Hide fixed
vyper/ast/natspec.py Fixed Show fixed Hide fixed
@@ -128,12 +129,15 @@ def format_annotation(self, value):

# TODO: handle cases where module is None or vy_ast.Module
if module_node.get("path") not in (None, "<unknown>"):
node_msg = f'{node_msg}contract "{module_node.path}:{node.lineno}", '
node_msg = self._format_contract_details(node_msg, module_node.path, node.lineno)
Copy link
Member

Choose a reason for hiding this comment

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

here we use module_node.path, but in the exception handlers added in this commit, resolved_path is used

Copy link
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.

looking pretty good.

i think the only thing left is that some of these matches in the pytest.raises() clauses can be improved if we use the chdir_tmp_path fixture, that way we don't need the wildcard in the regex.

Copy link
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.

thank you! @cyberthirst see if there is anything else you would like to add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants