Skip to content

Commit

Permalink
Ignore file on UnicodeDecodeError
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Jan 24, 2024
1 parent bb37b09 commit 6f59f7a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scantags.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ def grep_file(
Grep file
"""
matches = []
with open(filename, encoding="utf-8") as file:
for line_number, line in enumerate(file, start=1):
for match in line_regex.findall(line):
matches.append((line_number, match))
try:
with open(filename, encoding="utf-8") as file:
for line_number, line in enumerate(file, start=1):
for match in line_regex.findall(line):
matches.append((line_number, match))
except UnicodeDecodeError:
pass
return filename, matches


Expand Down

0 comments on commit 6f59f7a

Please sign in to comment.