Skip to content

Commit 58049eb

Browse files
committed
fix: check-yml encoding error
manage encoding error
1 parent 6db05e2 commit 58049eb

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

pre_commit_hooks/check_yaml.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ def main(argv: Sequence[str] | None = None) -> int:
6363
with open(filename, encoding='UTF-8') as f:
6464
load_fn(f)
6565
except ruamel.yaml.YAMLError as exc:
66-
print(exc)
66+
print(f'{filename}: Failed to yaml parse ({exc})')
67+
retval = 1
68+
except UnicodeDecodeError as exc:
69+
print(
70+
f'{filename}: Failed to read file due to encoding error '
71+
f'({exc})',
72+
)
6773
retval = 1
6874
return retval
6975

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
variables:
2+
- name: CopyRights
3+
value: "Copyright © $(date:YYYY)"

tests/check_yaml_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@pytest.mark.parametrize(
1010
('filename', 'expected_retval'), (
1111
('bad_yaml.notyaml', 1),
12+
('bad_encoding_yaml.yaml', 1),
1213
('ok_yaml.yaml', 0),
1314
),
1415
)

0 commit comments

Comments
 (0)