tweag / FawltyDeps

Python dependency checker
Other
189 stars 14 forks source link

Show a more helpful error message when failing to parse Python syntax #120

Open Nour-Mws opened 1 year ago

Nour-Mws commented 1 year ago

AST currently attempts to parse code from a Python file, and on failing, logs an error message and abandons that file (but continues parsing other files, depending on the CLI input). While this is the desired behavior, the user is only provided with an error message and no hints to debug or understand what caused the error beyond the file path and line.

An example is the following where the match expression (introduced in Python 3.10) is not recognized by FawltyDeps' AST run in 3.9.

match x:

Error message:

ERROR:fawltydeps.extract_imports:Could not parse code from entrypoint.py: invalid syntax (entrypoint.py, line 369)

It would be helpful to tell the user that the Python syntax might be invalid or not recognized by FawltyDeps because of a mismatch in the Python version.

mknorps commented 3 months ago

We should include a rule (enforced or suggested) that if you are running FD on code written in Python version X, FD must be run on version X or later. We should include a message similar to: "this error may happen because of the Python versions mismatch".