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

Hint at likely cause of ast parsing failure in error message #2786

Merged
merged 4 commits into from Jan 20, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/black/__init__.py
Expand Up @@ -1315,7 +1315,9 @@ def assert_equivalent(src: str, dst: str, *, pass_num: int = 1) -> None:
src_ast = parse_ast(src)
except Exception as exc:
raise AssertionError(
f"cannot use --safe with this file; failed to parse source file: {exc}"
f"cannot use --safe with this file; failed to parse source file AST: {exc}\n"
f"This could be caused by running black with an older python version "
JelleZijlstra marked this conversation as resolved.
Show resolved Hide resolved
f"that does not support new syntax used in your source file."
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will all get mushed into one line, which probably won't look great.

Not sure if it's worth it, but maybe we can raise a custom exception class here, and in the top-level code that displays errors to the user format it nicely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it isn't ideal.
That is more than I can take on at this time though(Covid/childcare problems).

) from exc

try:
Expand Down