-
Notifications
You must be signed in to change notification settings - Fork 491
BUG: pre-commit hook gets invoked after file deletion and crashes if excluded file does not exist #3687
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
Comments
But codespell doesn't invoke |
And codespell doesn't fail in this case: $ codespell /non/existent/file
$
EDIT: Got it, sorry about the misunderstanding: $ codespell --exclude-file /non/existent/file
Traceback (most recent call last):
File "/home/dp165978/.local/bin/codespell", line 8, in <module>
sys.exit(_script_main())
^^^^^^^^^^^^^^
File "/volatile/src/codespell/codespell_lib/_codespell.py", line 1102, in _script_main
return main(*sys.argv[1:])
^^^^^^^^^^^^^^^^^^^
File "/volatile/src/codespell/codespell_lib/_codespell.py", line 1261, in main
build_exclude_hashes(exclude_file, exclude_lines)
File "/volatile/src/codespell/codespell_lib/_codespell.py", line 726, in build_exclude_hashes
with open(filename, encoding="utf-8") as f:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/non/existent/file'
$ |
We could catch the $ ruff --config /non/existent/file
error: invalid value '/non/existent/file' for '--config <CONFIG_OPTION>'
tip: A `--config` flag must either be a path to a `.toml` configuration file
or a TOML `<KEY> = <VALUE>` pair overriding a specific configuration
option
It looks like you were trying to pass a path to a configuration file.
The path `/non/existent/file` does not point to a configuration file
For more information, try '--help'.
$
$ grep --file=/non/existent/file
grep: /non/existent/file: No such file or directory
$ |
Thanks for the quick reply!
No, it does not.
I think there's a misunderstanding: I totally do agree that exiting with an error is fine if the config file is missing. However, here we have a valid config but only one of the specified files within the config does not exist. I'd argue that this is not necessarily a reason to exit with a non-zero exit code - though of course it's up to you to decide ;) The following for example exits without an error:
|
This comment has been minimized.
This comment has been minimized.
@luzpaz Looks similar but unrelated to me: the EDIT: I would create a new issue for that. What's your opinion? Should codespell exit, or just emit a warning and keep going? |
Not sure what the implications for ignoring the warning would be... |
After having deleted a file, the
pre-commit
hook fails withwhere
and
when removing the
args
part it works again but I think it might be worth wile to either ignore the argument if the file does not exist and emit a warning and (or) not at all invokepre-commit
on deleted files.The text was updated successfully, but these errors were encountered: