Fix error handling
This commit is contained in:
parent
ba4d33373d
commit
da0f7adf97
1 changed files with 4 additions and 1 deletions
5
pat.py
Executable file → Normal file
5
pat.py
Executable file → Normal file
|
@ -28,7 +28,10 @@ for arg in argv[1:]:
|
||||||
file = stdin if arg == "-" else open(arg, "r")
|
file = stdin if arg == "-" else open(arg, "r")
|
||||||
read_result = file.read(bytes_to_read)
|
read_result = file.read(bytes_to_read)
|
||||||
except Exception as e:
|
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
|
continue
|
||||||
|
|
||||||
changes = len(list(filter(lambda c: not c in whitespace, read_result))) - 1
|
changes = len(list(filter(lambda c: not c in whitespace, read_result))) - 1
|
||||||
|
|
Loading…
Reference in a new issue