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

Fixit cli doesn't return non-zero exit code upon exceptions - add --exit-non-zero / --exit-zero options #258

Closed
zyv opened this issue Feb 14, 2023 · 2 comments

Comments

@zyv
Copy link

zyv commented Feb 14, 2023

Hello,

Commands like

python -m fixit.cli.apply_fix

can fail for some files in the CI silently and there is no way to detect it via the exit code - parsing also cannot be done reliably:

Encountered the following error while parsing source code in file /home/runner/work/xxx.py:
Syntax Error @ 59:19.
Incomplete input. Encountered 'operation', but expected ';', or 'NEWLINE'.

Linters like flake8 exit with non-zero code per default and they have an option like --exit-zero to ignore errors. Formatter black has option --check.

I would suggest to make fixit fail is some exception happens per default and add --exit-zero to opt out. Otherwise one can make this an opt-in functionality like --exit-non-zero.

I think this is quite important, especially after LibCST parser update, because problems can easily go unnoticed, if the is no way to make fixit return a non-zero code upon errors.

Thanks!

amyreese added a commit that referenced this issue Mar 15, 2023
This tracks exit codes based on the existence of violations and/or
errors when linting files.

- 0: everything clean
- 1: violations only
- 2: errors only
- 3: both violations and errors

Fixes #258

[ghstack-poisoned]
amyreese added a commit that referenced this issue Mar 15, 2023
This tracks exit codes based on the existence of violations and/or
errors when linting files.

- 0: everything clean
- 1: violations only
- 2: errors only
- 3: both violations and errors

Fixes #258

ghstack-source-id: 2c18d7a06f67313d29863e55a6cb45a97c655146
Pull Request resolved: #283
amyreese added a commit that referenced this issue Mar 15, 2023
…errors"

This tracks exit codes based on the existence of violations and/or
errors when linting files.

- 0: everything clean
- 1: violations only
- 2: errors only
- 3: both violations and errors

Fixes #258

[ghstack-poisoned]
amyreese added a commit that referenced this issue Mar 15, 2023
This tracks exit codes based on the existence of violations and/or
errors when linting files.

- 0: everything clean
- 1: violations only
- 2: errors only
- 3: both violations and errors

Fixes #258

[ghstack-poisoned]
amyreese added a commit that referenced this issue Mar 15, 2023
This tracks exit codes based on the existence of violations and/or
errors when linting files.

- 0: everything clean
- 1: violations only
- 2: errors only
- 3: both violations and errors

Fixes #258

ghstack-source-id: 2c18d7a06f67313d29863e55a6cb45a97c655146
Pull Request resolved: #283
@zyv
Copy link
Author

zyv commented Apr 2, 2023

Thank you @amyreese !

@samueljsb
Copy link
Contributor

This issue appears to have regressed:

$ cat t.py
this is not valid python

$ fixit fix -a t.py
t.py: EXCEPTION: Syntax Error @ 1:1.
parser error: error at 1:24: expected one of !=, %, &, (, *, **, +, ,, -, ., /, //, ;, <, <<, <=, ==, >, >=, >>, @, NEWLINE, [, ^, and, if, in, is, not, or, |

this is not valid python
^
Traceback (most recent call last):
  File "/private/tmp/tmpvenv-c329d/venv/lib/python3.11/site-packages/fixit/api.py", line 100, in fixit_bytes
    runner = LintRunner(path, content)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/tmpvenv-c329d/venv/lib/python3.11/site-packages/fixit/engine.py", line 55, in __init__
    self.module: Module = parse_module(source)
                          ^^^^^^^^^^^^^^^^^^^^
  File "/private/tmp/tmpvenv-c329d/venv/lib/python3.11/site-packages/libcst/_parser/entrypoints.py", line 109, in parse_module
    result = _parse(
             ^^^^^^^
  File "/private/tmp/tmpvenv-c329d/venv/lib/python3.11/site-packages/libcst/_parser/entrypoints.py", line 55, in _parse
    return parse(source_str)
           ^^^^^^^^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
parser error: error at 1:24: expected one of !=, %, &, (, *, **, +, ,, -, ., /, //, ;, <, <<, <=, ==, >, >=, >>, @, NEWLINE, [, ^, and, if, in, is, not, or, |

this is not valid python
^
🛠️  1 file checked, 1 file with errors 🛠️

$ echo $?
0

Fixit version 2.1.0, Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants