CI: Catch UnicodeDecodeError in whitespace-check.py

Changes behavior when a non-UTF-8 character is found from exiting the
script with a Python exception traceback and no clue which file had it
to reporting the filename and continuing to check the remaining files.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
This commit is contained in:
Alan Coopersmith 2026-03-29 11:23:56 -07:00
parent 16ca2c7a11
commit cd6edf4131

View file

@ -94,7 +94,13 @@ def main():
reset = ""
for file in args.files:
lines = [l.rstrip("\n") for l in file.open().readlines()]
try:
lines = [l.rstrip("\n") for l in file.open().readlines()]
except UnicodeDecodeError as e:
print(f"{red}ERROR: {e} in {file}:{reset}", file=sys.stderr)
print(f"{'-' * 72}", file=sys.stderr)
have_errors = True
continue
errors = []
errors.extend(test_tab_indent(lines))