Skip to content

Commit 8a39175

Browse files
authored
fix(adbc_drivers_dev/rat): handle binary files more gracefully (#16)
## What's Changed Makes the RAT pre-commit command mores resilient when it encounters binary files. Without this change, pre-commit just fails with a cryptic UnicdoeDecodeError without any context for which file failed. Handling rat-excludes happens below this line so excluding any files you suspect may be the cause doesn't help.
1 parent 8ba235d commit 8a39175

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

adbc_drivers_dev/rat/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,12 @@ def main():
153153
lines = []
154154
for _ in range(20):
155155
lines.append(f.readline())
156-
157-
content = b" ".join(lines).decode("utf-8")
156+
try:
157+
content = b" ".join(lines).decode("utf-8")
158+
except UnicodeDecodeError:
159+
# decode will fail on non-text files so just use empty
160+
# content so RAT will fail if the file isn't excluded
161+
content = ""
158162
content = sep_re.sub(" ", content)
159163

160164
if not copyright_re.search(content):

0 commit comments

Comments
 (0)