-
-
Notifications
You must be signed in to change notification settings - Fork 819
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]: add missing filename to syntax exceptions #4343
Merged
charles-cooper
merged 37 commits into
vyperlang:master
from
sandbubbles:fix/syntax-exception-missing-filename
Dec 13, 2024
+111
−5
Merged
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
4425feb
add path info to syntax exception
sandbubbles 3316865
set path for natspec exceptions
sandbubbles 90723e1
lint
sandbubbles bdf5a42
rewrite the path attribute
sandbubbles 363cf1d
test natspec exception contains file
sandbubbles 241511b
test version exception contains filename
sandbubbles b3c8ef5
test imported invalid compiler version is attributed correctly
sandbubbles 02c5765
check syntax exception in json contains filename
sandbubbles 548d583
check the exception is attributed to the correct file
sandbubbles 67dcfb8
test syntax exceptions report file correctly
sandbubbles 2dded1a
fix isort errors
sandbubbles 2dfa033
refactor[ux]: add `venom` as `experimental-codegen` alias (#4337)
sandbubbles 5637913
fix[ci]: fix README encoding in `setup.py` (#4348)
charles-cooper b6591b4
feat[docs]: add Telegram badge to README.md (#4342)
rafael-abuawad 9450428
extract adding contract info into a function
sandbubbles 97b3abe
update error message verification to include line number
sandbubbles 1b0e02a
Merge branch 'master' into fix/syntax-exception-missing-filename
charles-cooper 05e24d6
wrap parse_natspec in a try catch to add path
sandbubbles 5101a27
remove changes to _annotate functions
sandbubbles 7f44b10
rename method to "_format_contract_details"
sandbubbles 88174e7
lint
sandbubbles e66da98
remove redundant "pass"
sandbubbles bf3ee5b
change path to resolved_path in exceptions
sandbubbles bd0d2d3
wrap path in safe_relpath
sandbubbles b6adc0b
lint
sandbubbles 43edf77
add chdir_tmp_path to test fixtures and remove wildcards
sandbubbles 96bac14
remove chdir_tmp_path when make_input_bundle is not used
sandbubbles af391a6
check resolved_path is not unknown
sandbubbles c09dc65
use only the msg of SyntaxError
sandbubbles 6ca0cbb
Merge branch 'master' into fix/syntax-exception-missing-filename
sandbubbles fd8d78d
adjust the offset by 1
sandbubbles 78362e6
test offset points to correct place
sandbubbles 5ea4e2c
add comment
sandbubbles 5022cfd
nits
charles-cooper 7f0b3f4
fix lint
charles-cooper 531cdca
move comment
charles-cooper 8e87405
Merge branch 'master' into fix/syntax-exception-missing-filename
charles-cooper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ def __init__(self, message="Error Message not found.", *items, hint=None, prev_d | |
self.lineno = None | ||
self.col_offset = None | ||
self.annotations = None | ||
self.path = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for clarity, let's rename this to |
||
|
||
if len(items) == 1 and isinstance(items[0], tuple) and isinstance(items[0][0], int): | ||
# support older exceptions that don't annotate - remove this in the future! | ||
|
@@ -127,13 +128,18 @@ def format_annotation(self, value): | |
module_node = node.module_node | ||
|
||
# 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}", ' | ||
if module_node.get("resolved_path") not in (None, "<unknown>"): | ||
node_msg = self._format_contract_details( | ||
node_msg, module_node.resolved_path, node.lineno | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we check |
||
) | ||
|
||
fn_node = node.get_ancestor(vy_ast.FunctionDef) | ||
if fn_node: | ||
node_msg = f'{node_msg}function "{fn_node.name}", ' | ||
|
||
elif self.path is not None: | ||
node_msg = self._format_contract_details(node_msg, self.path, node.lineno) | ||
charles-cooper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
col_offset_str = "" if node.col_offset is None else str(node.col_offset) | ||
node_msg = f"{node_msg}line {node.lineno}:{col_offset_str} \n{source_annotation}\n" | ||
|
||
|
@@ -151,6 +157,11 @@ def _add_hint(self, msg): | |
return msg | ||
return msg + f"\n (hint: {self.hint})" | ||
|
||
def _format_contract_details(self, msg, path, lineno): | ||
from vyper.utils import safe_relpath | ||
charles-cooper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return f'{msg}contract "{safe_relpath(path)}:{lineno}", ' | ||
|
||
def __str__(self): | ||
return self._add_hint(self._str_helper()) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add docs to comment: