Skip to content

Commit a366a9e

Browse files
committed
report unicode decode failures nicely
1 parent 0595f57 commit a366a9e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/etc/tidy.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@ def report_err(s):
1818
print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
1919
err=1
2020

21-
for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
22-
if line.find('\t') != -1 and fileinput.filename().find("Makefile") == -1:
23-
report_err("tab character")
24-
25-
if not autocrlf and line.find('\r') != -1:
26-
report_err("CR character")
27-
28-
if line.endswith(" \n") or line.endswith("\t\n"):
29-
report_err("trailing whitespace")
30-
31-
line_len = len(line)-2 if autocrlf else len(line)-1
32-
if line_len > cols:
33-
report_err("line longer than %d chars" % cols)
21+
try:
22+
for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")):
23+
if (line.find('\t') != -1 and
24+
fileinput.filename().find("Makefile") == -1):
25+
report_err("tab character")
26+
if not autocrlf and line.find('\r') != -1:
27+
report_err("CR character")
28+
if line.endswith(" \n") or line.endswith("\t\n"):
29+
report_err("trailing whitespace")
30+
line_len = len(line)-2 if autocrlf else len(line)-1
31+
if line_len > cols:
32+
report_err("line longer than %d chars" % cols)
33+
except UnicodeDecodeError, e:
34+
report_err("UTF-8 decoding error " + str(e))
3435

3536

3637
sys.exit(err)

0 commit comments

Comments
 (0)