Skip to content

Exit properly on exclude-file error #3688

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions codespell_lib/_codespell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,12 +1180,13 @@
options.ignore_words
)
for ignore_words_file in ignore_words_files:
if not os.path.isfile(ignore_words_file):
try:
build_ignore_words(ignore_words_file, ignore_words, ignore_words_cased)
except OSError as e:
return _usage_error(
parser,
f"ERROR: cannot find ignore-words file: {ignore_words_file}",
f"ERROR: cannot read ignore-words-file {e.filename}: {e.strerror}",
)
build_ignore_words(ignore_words_file, ignore_words, ignore_words_cased)

uri_regex = options.uri_regex or uri_regex_def
try:
Expand Down Expand Up @@ -1258,7 +1259,13 @@
if options.exclude_file:
exclude_files = flatten_clean_comma_separated_arguments(options.exclude_file)
for exclude_file in exclude_files:
build_exclude_hashes(exclude_file, exclude_lines)
try:
build_exclude_hashes(exclude_file, exclude_lines)
except OSError as e:
return _usage_error(

Check warning on line 1265 in codespell_lib/_codespell.py

View check run for this annotation

Codecov / codecov/patch

codespell_lib/_codespell.py#L1264-L1265

Added lines #L1264 - L1265 were not covered by tests
parser,
f"ERROR: cannot read exclude-file {e.filename}: {e.strerror}",
)

file_opener = FileOpener(
options.hard_encoding_detection,
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ignore = [
]

[tool.ruff.lint.mccabe]
max-complexity = 45
max-complexity = 46

[tool.ruff.lint.per-file-ignores]
"codespell_lib/_codespell.py" = ["A003"]
Expand All @@ -171,6 +171,6 @@ max-complexity = 45
[tool.ruff.lint.pylint]
allow-magic-value-types = ["bytes", "int", "str",]
max-args = 13
max-branches = 48
max-returns = 12
max-branches = 49
max-returns = 13
max-statements = 119