From d4718f823f0f10cf4babae330d680ae24b7bdcf2 Mon Sep 17 00:00:00 2001 From: loathingKernel <142770+loathingKernel@users.noreply.github.com> Date: Sat, 25 Jun 2022 21:51:32 +0300 Subject: [PATCH] Use custom exception to overload `log.error` and `log.fatal` in `egl_import` and `egl_export` --- rare/lgndr/core.py | 20 ++++++++++++++++++++ rare/lgndr/exception.py | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 rare/lgndr/exception.py diff --git a/rare/lgndr/core.py b/rare/lgndr/core.py index e512bc8a..0635cc85 100644 --- a/rare/lgndr/core.py +++ b/rare/lgndr/core.py @@ -10,10 +10,14 @@ from legendary.utils.selective_dl import get_sdl_appname from legendary.core import LegendaryCore as LegendaryCoreReal from .manager import DLManager +from .exception import LgndrException class LegendaryCore(LegendaryCoreReal): + def __log_exception(self, error): + raise LgndrException(error) + def prepare_download(self, app_name: str, base_path: str = '', status_q: Queue = None, max_shm: int = 0, max_workers: int = 0, force: bool = False, disable_patching: bool = False, @@ -225,3 +229,19 @@ class LegendaryCore(LegendaryCoreReal): self.log.info('Deleting now untagged files.') self.uninstall_tag(old_igame) self.install_game(old_igame) + + def egl_import(self, app_name): + __log_error = self.log.error + __log_fatal = self.log.fatal + self.log.error = self.__log_exception + self.log.fatal = self.__log_exception + super(LegendaryCore, self).egl_import(app_name) + self.log.error = __log_error + self.log.fatal = __log_fatal + + def egl_export(self, app_name): + __log_error = self.log.error + self.log.error = self.__log_exception + super(LegendaryCore, self).egl_export(app_name) + self.log.error = __log_error + diff --git a/rare/lgndr/exception.py b/rare/lgndr/exception.py new file mode 100644 index 00000000..13f08aca --- /dev/null +++ b/rare/lgndr/exception.py @@ -0,0 +1,4 @@ +class LgndrException(RuntimeError): + def __init__(self, message="Error in Legendary"): + self.message = message + super(LgndrException, self).__init__(self.message)