diff --git a/SNIClient.py b/SNIClient.py index 222ed54f..19440e1d 100644 --- a/SNIClient.py +++ b/SNIClient.py @@ -633,7 +633,13 @@ async def game_watcher(ctx: SNIContext) -> None: if not ctx.client_handler: 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): 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() - 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: diff --git a/worlds/AutoSNIClient.py b/worlds/AutoSNIClient.py index 2b984d9c..b3f40be2 100644 --- a/worlds/AutoSNIClient.py +++ b/worlds/AutoSNIClient.py @@ -1,6 +1,7 @@ from __future__ import annotations import abc +import logging from typing import TYPE_CHECKING, ClassVar, Dict, Iterable, Tuple, Any, Optional, Union from typing_extensions import TypeGuard @@ -60,8 +61,12 @@ class AutoSNIClientRegister(abc.ABCMeta): @staticmethod async def get_handler(ctx: SNIContext) -> Optional[SNIClient]: for _game, handler in AutoSNIClientRegister.game_handlers.items(): - if await handler.validate_rom(ctx): - return handler + try: + if await handler.validate_rom(ctx): + return handler + except Exception as e: + text_file_logger = logging.getLogger() + text_file_logger.exception(e) return None