1
0
Fork 0
mirror of synced 2024-06-02 02:34:40 +12:00

Lgndr: Handle exceptions in the unlock decorator

This commit is contained in:
loathingKernel 2023-12-10 13:47:07 +02:00
parent 9dd078aa92
commit 5a2c9ae444
No known key found for this signature in database
GPG key ID: CE0C72D0B53821FD
3 changed files with 23 additions and 18 deletions

View file

@ -43,8 +43,12 @@ class LegendaryCLI(LegendaryCLIReal):
def unlock_installed(func):
@functools.wraps(func)
def unlock(self, *args, **kwargs):
ret = func(self, *args, **kwargs)
self.core.lgd._installed_lock.release(force=True)
try:
ret = func(self, *args, **kwargs)
except Exception as e:
raise e
finally:
self.core.lgd._installed_lock.release(force=True)
return ret
return unlock

View file

@ -1,5 +1,6 @@
import functools
import json
import logging
import os
from multiprocessing import Queue
from uuid import uuid4
@ -16,7 +17,7 @@ from legendary.models.game import Game, InstalledGame
from legendary.models.manifest import ManifestMeta
from rare.lgndr.downloader.mp.manager import DLManager
from rare.lgndr.glue.exception import LgndrException, LgndrCoreLogHandler
from rare.lgndr.glue.exception import LgndrException, LgndrLogHandler
legendary.core.DLManager = DLManager
@ -26,15 +27,19 @@ class LegendaryCore(LegendaryCoreReal):
def __init__(self, override_config=None, timeout=10.0):
super(LegendaryCore, self).__init__(override_config=override_config, timeout=timeout)
self.handler = LgndrCoreLogHandler()
self.handler = LgndrLogHandler(logging.CRITICAL)
self.log.addHandler(self.handler)
@staticmethod
def unlock_installed(func):
@functools.wraps(func)
def unlock(self, *args, **kwargs):
ret = func(self, *args, **kwargs)
self.lgd._installed_lock.release(force=True)
try:
ret = func(self, *args, **kwargs)
except Exception as e:
raise e
finally:
self.lgd._installed_lock.release(force=True)
return ret
return unlock

View file

@ -14,19 +14,15 @@ class LgndrWarning(RuntimeWarning):
super(LgndrWarning, self).__init__(self.message)
class LgndrCLILogHandler(logging.Handler):
def emit(self, record: logging.LogRecord) -> None:
# lk: FATAL is the same as CRITICAL
if record.levelno == logging.ERROR or record.levelno == logging.CRITICAL:
raise LgndrException(record.getMessage())
# if record.levelno < logging.ERROR or record.levelno == logging.WARNING:
# warnings.warn(record.getMessage())
# Minimum exception levels per class to get back useful error strings
# CLI: ERROR
# Core: CRITICAL (FATAL)
class LgndrLogHandler(logging.Handler):
def __init__(self, level=logging.NOTSET):
super().__init__(level=level)
class LgndrCoreLogHandler(logging.Handler):
def emit(self, record: logging.LogRecord) -> None:
# lk: FATAL is the same as CRITICAL
if record.levelno == logging.CRITICAL:
if record.levelno >= self.level:
raise LgndrException(record.getMessage())
# if record.levelno < logging.CRITICAL:
# if self.level > record.levelno >= logging.WARNING:
# warnings.warn(record.getMessage())