From 01a214851de1fffd76e829a8aff884d6e15dc5c3 Mon Sep 17 00:00:00 2001 From: None <190783071+CodeBormen@users.noreply.github.com> Date: Sun, 15 Mar 2026 01:11:29 -0500 Subject: [PATCH] fix: catch all exceptions in entity resolution to avoid breaking EPG refresh Previously only UnicodeDecodeError/UnicodeEncodeError were caught. Unexpected errors like disk full or permission denied would propagate and crash the EPG refresh, which would have succeeded before the preprocessing step existed. Now all exceptions are caught and logged, leaving the original file untouched for lxml to handle as before. --- apps/epg/tasks.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/epg/tasks.py b/apps/epg/tasks.py index 5d567e6e..df1e0836 100644 --- a/apps/epg/tasks.py +++ b/apps/epg/tasks.py @@ -84,8 +84,10 @@ def _resolve_html_entities(file_path): Processes line-by-line to keep memory usage low, writes to a temp file, then atomically replaces the original. Honors the encoding declared - in the XML declaration. If the file cannot be decoded cleanly it is - left untouched for lxml to handle with its own recovery mode. + in the XML declaration. + + This function is strictly additive — on any error the original file is + left untouched so lxml can handle it as it always did. """ # Read the first 200 bytes to detect encoding from the XML declaration with open(file_path, 'rb') as f: @@ -102,10 +104,12 @@ def _resolve_html_entities(file_path): os.replace(temp_path, file_path) success = True logger.debug(f"Resolved HTML entities in {file_path} (encoding: {encoding})") - except (UnicodeDecodeError, UnicodeEncodeError): - # Leave the file untouched for lxml to handle with its own - # encoding detection and recovery mode. - logger.debug(f"Skipping entity resolution for {file_path}: encoding error with {encoding}") + except Exception as e: + # On any error, leave the original file untouched for lxml to + # handle with its own encoding detection and recovery mode. + # This ensures the preprocessing step never breaks a previously + # working EPG refresh. + logger.debug(f"Skipping entity resolution for {file_path}: {e}") finally: if not success and os.path.exists(temp_path): os.unlink(temp_path)