-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Improve parse error readability #5068
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
5d8d6e8
d8ae509
231d7d9
18b58a2
d31be90
08f2a57
2550fe8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,16 +80,26 @@ def lib2to3_parse( | |
| faulty_line = lines[lineno - 1] | ||
| except IndexError: | ||
| faulty_line = "<line number missing in source>" | ||
| errors[grammar.version] = InvalidInput( | ||
| f"Cannot parse{tv_str}: {lineno}:{column}: {faulty_line}" | ||
| ) | ||
| error_msg = ( | ||
| f"Cannot parse{tv_str}: {lineno}:{column}\n" | ||
| f" {faulty_line}\n" | ||
| f" {' ' * (column - 1)}^\n" | ||
| "SyntaxError: invalid syntax" | ||
| ) | ||
|
|
||
| errors[grammar.version] = InvalidInput(error_msg) | ||
|
|
||
| except TokenError as te: | ||
| # In edge cases these are raised; and typically don't have a "faulty_line". | ||
| lineno, column = te.args[1] | ||
| errors[grammar.version] = InvalidInput( | ||
| f"Cannot parse{tv_str}: {lineno}:{column}: {te.args[0]}" | ||
| ) | ||
| error_msg = ( | ||
| f"Cannot parse{tv_str}: {lineno}:{column}\n" | ||
| f" {te.args[0]}\n" | ||
| f" {' ' * (column - 1)}^\n" | ||
| "SyntaxError: invalid syntax" | ||
|
||
| ) | ||
|
|
||
| errors[grammar.version] = InvalidInput(error_msg) | ||
|
|
||
| else: | ||
| # Choose the latest version when raising the actual parsing error. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.