Skip to content

Commit c11c548

Browse files
committed
check-json: resolve TODO
1 parent 66250ba commit c11c548

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pre_commit_hooks/check_json.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
1414
with open(filename, 'rb') as f:
1515
try:
1616
json.load(f)
17-
# TODO: need UnicodeDecodeError?
18-
except (ValueError, UnicodeDecodeError) as exc:
17+
except ValueError as exc:
1918
print(f'{filename}: Failed to json decode ({exc})')
2019
retval = 1
2120
return retval

tests/check_json_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ def test_main(capsys, filename, expected_retval):
1717
if expected_retval == 1:
1818
stdout, _ = capsys.readouterr()
1919
assert filename in stdout
20+
21+
22+
def test_non_utf8_file(tmpdir):
23+
f = tmpdir.join('t.json')
24+
f.write_binary(b'\xa9\xfe\x12')
25+
assert main((str(f),))

0 commit comments

Comments
 (0)