From 857025e216cd23ec9421452f80d5db9ad686aebf Mon Sep 17 00:00:00 2001 From: "Jamie (Bear) Murphy" <1613241+ITJamie@users.noreply.github.com> Date: Fri, 20 May 2022 17:39:35 +0100 Subject: [PATCH] add unicode error catching So i found this when i hit some non unicode files. examples of some errors caught with this this is a rough fix but at least allows tests to complete. without this catch the script would crash ``` unable to process file (path removed) due to unicode decode error 'utf-8' codec can't decode byte 0xa7 in position 195: invalid start byte unable to process file (path removed) due to unicode decode error 'utf-8' codec can't decode byte 0xa1 in position 33: invalid start byte ``` --- zulint/custom_rules.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zulint/custom_rules.py b/zulint/custom_rules.py index c40ec16..7eab9b0 100644 --- a/zulint/custom_rules.py +++ b/zulint/custom_rules.py @@ -134,7 +134,12 @@ def custom_check_file( failed = False with open(fn, encoding="utf8") as f: - contents = f.read() + try: + contents = f.read() + except UnicodeDecodeError as e: + print(f"unable to process file {fn} due to unicode decode error") + print(e) + return True line_starts = [m.start() for m in re.finditer(r"^.", contents, re.M | re.S)] rules_to_apply = self.get_rules_applying_to_fn(fn=fn, rules=self.rules)