From a5742585f78534ab62ebe47aff50864769c81b92 Mon Sep 17 00:00:00 2001 From: y8o <247892592+y8olol@users.noreply.github.com> Date: Thu, 30 Apr 2026 23:51:24 -0400 Subject: [PATCH] Fix download_file silently caching failed HTTP responses If the BCData repo doesn't have a file for the current game version, requests.get() returns a 404 with HTML content. The old code wrote this to disk and cached it, so subsequent runs would read corrupt data without any useful error message. Now check the status code before caching and return None on failure, letting callers surface a meaningful error. Also handle ConnectionError explicitly with a clear message instead of raising an unhandled exception. --- src/BCSFE_Python/game_data_getter.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/BCSFE_Python/game_data_getter.py b/src/BCSFE_Python/game_data_getter.py index 3da4c1ad..8f7e4cc5 100644 --- a/src/BCSFE_Python/game_data_getter.py +++ b/src/BCSFE_Python/game_data_getter.py @@ -14,7 +14,7 @@ def download_file( file_name: str, get_data: bool = True, print_progress: bool = True, -) -> bytes: +) -> Optional[bytes]: """ Downloads the file. @@ -43,7 +43,21 @@ def download_file( helper.WHITE, ) url = URL + game_version + "/" + pack_name + "/" + file_name - response = requests.get(url) + try: + response = requests.get(url) + except requests.exceptions.ConnectionError: + helper.colored_text( + f"Failed to download game data &{file_name}&: no internet connection.", + helper.RED, + ) + return None + + if response.status_code != 200: + helper.colored_text( + f"Failed to download game data &{file_name}& from &{pack_name}& (HTTP {response.status_code}). The file may not exist for version &{game_version}&.", + helper.RED, + ) + return None helper.create_dirs(path) helper.write_file_bytes(file_path, response.content)