SNIClient: log exceptions and keep task alive (#3911)
* SNIClient: log exceptions and keep task alive * also log errors in `get_handler` and disconnect if error in `game_watcher`
This commit is contained in:
parent
0b5c7fe8a9
commit
085b655ad9
16
SNIClient.py
16
SNIClient.py
|
@ -633,7 +633,13 @@ async def game_watcher(ctx: SNIContext) -> None:
|
||||||
if not ctx.client_handler:
|
if not ctx.client_handler:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
rom_validated = await ctx.client_handler.validate_rom(ctx)
|
try:
|
||||||
|
rom_validated = await ctx.client_handler.validate_rom(ctx)
|
||||||
|
except Exception as e:
|
||||||
|
snes_logger.error(f"An error occurred, see logs for details: {e}")
|
||||||
|
text_file_logger = logging.getLogger()
|
||||||
|
text_file_logger.exception(e)
|
||||||
|
rom_validated = False
|
||||||
|
|
||||||
if not rom_validated or (ctx.auth and ctx.auth != ctx.rom):
|
if not rom_validated or (ctx.auth and ctx.auth != ctx.rom):
|
||||||
snes_logger.warning("ROM change detected, please reconnect to the multiworld server")
|
snes_logger.warning("ROM change detected, please reconnect to the multiworld server")
|
||||||
|
@ -649,7 +655,13 @@ async def game_watcher(ctx: SNIContext) -> None:
|
||||||
|
|
||||||
perf_counter = time.perf_counter()
|
perf_counter = time.perf_counter()
|
||||||
|
|
||||||
await ctx.client_handler.game_watcher(ctx)
|
try:
|
||||||
|
await ctx.client_handler.game_watcher(ctx)
|
||||||
|
except Exception as e:
|
||||||
|
snes_logger.error(f"An error occurred, see logs for details: {e}")
|
||||||
|
text_file_logger = logging.getLogger()
|
||||||
|
text_file_logger.exception(e)
|
||||||
|
await snes_disconnect(ctx)
|
||||||
|
|
||||||
|
|
||||||
async def run_game(romfile: str) -> None:
|
async def run_game(romfile: str) -> None:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import abc
|
import abc
|
||||||
|
import logging
|
||||||
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, Tuple, Any, Optional, Union
|
from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, Tuple, Any, Optional, Union
|
||||||
|
|
||||||
from typing_extensions import TypeGuard
|
from typing_extensions import TypeGuard
|
||||||
|
@ -60,8 +61,12 @@ class AutoSNIClientRegister(abc.ABCMeta):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_handler(ctx: SNIContext) -> Optional[SNIClient]:
|
async def get_handler(ctx: SNIContext) -> Optional[SNIClient]:
|
||||||
for _game, handler in AutoSNIClientRegister.game_handlers.items():
|
for _game, handler in AutoSNIClientRegister.game_handlers.items():
|
||||||
if await handler.validate_rom(ctx):
|
try:
|
||||||
return handler
|
if await handler.validate_rom(ctx):
|
||||||
|
return handler
|
||||||
|
except Exception as e:
|
||||||
|
text_file_logger = logging.getLogger()
|
||||||
|
text_file_logger.exception(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue