From dac701334e7bd024ebe5dff0c908449d167cf726 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 10 Feb 2024 17:44:55 -0500 Subject: [PATCH 1/2] Hotfix storing screenshots when igdb fetch fails --- backend/handler/fs_handler/fs_resources_handler.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/backend/handler/fs_handler/fs_resources_handler.py b/backend/handler/fs_handler/fs_resources_handler.py index db49fc42f..08551ef2f 100644 --- a/backend/handler/fs_handler/fs_resources_handler.py +++ b/backend/handler/fs_handler/fs_resources_handler.py @@ -2,7 +2,7 @@ import os import shutil from pathlib import Path from urllib.parse import quote - +from urllib3.exceptions import ProtocolError import requests from config import RESOURCES_BASE_PATH from handler.fs_handler import ( @@ -135,11 +135,13 @@ class FSResourceHandler(FSHandler): q_rom_name = quote(rom_name) path_cover_l = f"{fs_slug}/{q_rom_name}/cover/{CoverSize.BIG.value}.{file_ext}" - path_cover_s = f"{fs_slug}/{q_rom_name}/cover/{CoverSize.SMALL.value}.{file_ext}" + path_cover_s = ( + f"{fs_slug}/{q_rom_name}/cover/{CoverSize.SMALL.value}.{file_ext}" + ) artwork_path = f"{RESOURCES_BASE_PATH}/{fs_slug}/{rom_name}/cover" Path(artwork_path).mkdir(parents=True, exist_ok=True) return path_cover_l, path_cover_s, artwork_path - + def _store_screenshot(self, fs_slug: str, rom_name: str, url: str, idx: int): """Store roms resources in filesystem @@ -154,7 +156,10 @@ class FSResourceHandler(FSHandler): if res.status_code == 200: Path(screenshot_path).mkdir(parents=True, exist_ok=True) with open(f"{screenshot_path}/{screenshot_file}", "wb") as f: - shutil.copyfileobj(res.raw, f) + try: + shutil.copyfileobj(res.raw, f) + except ProtocolError: + pass def _get_screenshot_path(self, fs_slug: str, rom_name: str, idx: str): """Returns rom cover filesystem path adapted to frontend folder structure From aad0b3bd3651206609866f400fbac1527261caf6 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sat, 10 Feb 2024 18:07:04 -0500 Subject: [PATCH 2/2] add warning message to logs --- backend/handler/fs_handler/fs_resources_handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/handler/fs_handler/fs_resources_handler.py b/backend/handler/fs_handler/fs_resources_handler.py index 08551ef2f..e4beba6cf 100644 --- a/backend/handler/fs_handler/fs_resources_handler.py +++ b/backend/handler/fs_handler/fs_resources_handler.py @@ -3,6 +3,7 @@ import shutil from pathlib import Path from urllib.parse import quote from urllib3.exceptions import ProtocolError +from logger.logger import log import requests from config import RESOURCES_BASE_PATH from handler.fs_handler import ( @@ -159,7 +160,9 @@ class FSResourceHandler(FSHandler): try: shutil.copyfileobj(res.raw, f) except ProtocolError: - pass + log.warning( + f"Failure writing screenshot {url} to file (ProtocolError)" + ) def _get_screenshot_path(self, fs_slug: str, rom_name: str, idx: str): """Returns rom cover filesystem path adapted to frontend folder structure