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

Bad formatting of error messages about EOF in multi-line statements #2317

Closed
Jackenmen opened this issue Jun 8, 2021 · 11 comments · Fixed by #2343
Closed

Bad formatting of error messages about EOF in multi-line statements #2317

Jackenmen opened this issue Jun 8, 2021 · 11 comments · Fixed by #2343
Labels
C: configuration CLI and configuration good first issue Good for newcomers S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request

Comments

@Jackenmen
Copy link
Contributor

Describe the bug

"EOF in multi-line statement" error is shown to the user as the raw tuple it was returned as, rather than in a nicely formatted message.

To Reproduce

For example:

  1. Take this (invalid) file:
print(
  1. Run Black on it with no arguments
  2. See a message with the EOF error being shown as a raw tuple representation:
error: cannot format test_black.py: ('EOF in multi-line statement', (2, 0))
Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

A bit more nicely formatted error message.

Environment (please complete the following information):

  • Version:
  • OS and Python version:

Does this bug also happen on main?

Yes.

Additional context

For comparison, here's how I'm assuming the error should look like:

error: cannot format test_black.py: Cannot parse: 1:7: print([)
Oh no! 💥 💔 💥
1 file failed to reformat.

which is what you get in output when you try to format:

print([)
@felix-hilden felix-hilden added the C: configuration CLI and configuration label Jun 8, 2021
@felix-hilden
Copy link
Collaborator

Many thanks for reporting!

@Jackenmen
Copy link
Contributor Author

It appears to be about TokenError (and potentially also IndentationError) exception leaking out from lib2to3_parse() call. Should the lib2to3_parse() function just be updated to handle these 2 errors or is there some other solution that would be preferred here?

@ichard26 ichard26 added S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request good first issue Good for newcomers labels Jun 8, 2021
@ichard26
Copy link
Collaborator

Eh, it seems to be just easier to add those two exceptions to the except definition than come up withe something more complicated.

@tanvimoharir
Copy link
Contributor

Hi,
I would like to work on this. (I'm new to this).
Thanks

@felix-hilden
Copy link
Collaborator

Hi, thanks for considering contributing! And welcome 😄 I don't think anyone's currently working on it so feel free to attempt a fix 👍 Jack's messages above should get you in the right direction.

@avishmehta68710
Copy link

Hi
Is this issue open or is it solved
Thanks

@surfaceowl
Copy link

This EOF in multi-line statement error is also triggered if you are using a jupyter notebook and have a cell with sample terminal command set as a code cell rather than Markdown or Raw NBConvert.

@Last-Winner
Copy link

Error compiling contract, Error message:
tokenize.TokenError: ('EOF in multi-line statement', (230, 0))

The above exception was the direct cause of the following exception:

vyper.exceptions.SyntaxException: EOF in multi-line statement
line 230:0
229 227 ],
---> 230
---------^

@amarvin
Copy link

amarvin commented Dec 7, 2023

I still get this error EOF in multi-line statement when trying to format using black a Jupyter Notebook cell that contains an incorrectly formatted f-string. Here's a minimal example cell:

print(f"{"#"}")

It took me a while to find which of the cells caused the error, as the error doesn't say. Running the problematic cell in a Python terminal shows that it still expected additional input to complete the statement, hence why an error was thrown by black when the cell unexpectedly ended. The correct cell contents should be:

print(f"{'#'}")

I posted about it in Stack Overflow on a similar question https://stackoverflow.com/a/77622709/6068036

@JelleZijlstra
Copy link
Collaborator

@amarvin that's #3746.

@amarvin
Copy link

amarvin commented Dec 7, 2023

@amarvin that's #3746.

Good point! That should cover this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: configuration CLI and configuration good first issue Good for newcomers S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants