Fix error handling

This commit is contained in:
endie 2021-03-30 23:51:18 +00:00
parent ba4d33373d
commit da0f7adf97

5
pat.py Executable file → Normal file
View file

@ -28,7 +28,10 @@ for arg in argv[1:]:
file = stdin if arg == "-" else open(arg, "r")
read_result = file.read(bytes_to_read)
except Exception as e:
print("Error reading %s: %s" % (file.name, e), file=stderr)
print(
f"Error {f'reading {file.name}' if 'file' in globals() else 'opening file'}: {e}",
file=stderr,
)
continue
changes = len(list(filter(lambda c: not c in whitespace, read_result))) - 1