Skip to content

Commit 85630ad

Browse files
authored
fixed encoding error handling
1 parent 974d39d commit 85630ad

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

wfc/logger.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def log(log_type: str, text: str):
2424
def show_summary():
2525
current_date = datetime.now()
2626
size_saved_mb = 0.0
27-
with open(paths.LOG_PATH, "r", encoding=ENCODING) as log_file:
27+
with open(paths.LOG_PATH, "r", encoding=ENCODING, errors="ignore") as log_file:
2828
for line in log_file:
2929
if "Program startup" in line:
3030
continue
@@ -46,16 +46,29 @@ def show_summary():
4646

4747
def _extract_line_data(line: str) -> Tuple[str, str, str, str]:
4848
filename_regex = r"(FILE|DIR): (.*?) SIZE: ([\d.]+) (GB|MB) REASON: (.+)"
49-
if not (match := re.search(filename_regex, line)):
49+
50+
# Match the main filename pattern
51+
match = re.search(filename_regex, line)
52+
if not match:
5053
return "", "", "", ""
51-
timestamp = re.search(r"(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}:\d{2})", line)[1]
54+
55+
# Match the timestamp pattern
56+
timestamp_match = re.search(r"(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}:\d{2})", line)
57+
timestamp = (
58+
timestamp_match[1] if timestamp_match else ""
59+
) # Check if timestamp was found
60+
5261
filetype = match[1]
5362
size_value = float(match[3])
5463
size_unit = match[4]
64+
65+
# Convert GB to MB if necessary
5566
if size_unit == "GB":
5667
size_value *= 1024 # Convert GB to MB
68+
5769
size = f"{size_value:.2f} MB"
5870
reason = match[5]
71+
5972
return timestamp, filetype, size, reason
6073

6174

0 commit comments

Comments
 (0)