paper-dynasty-discord/exceptions.py
Cal Corum bfd72ae0f5 Update logging to RotatingFileHandler
Add auto game end
Calculate stats and decisions
Support raising instantiated exceptions
2024-11-09 23:14:54 -06:00

52 lines
1.1 KiB
Python

import logging
from typing import Literal
logger = logging.getLogger('discord_app')
def log_exception(e: Exception, msg: str = '', level: Literal['debug', 'error', 'info', 'warn'] = 'error'):
if level == 'debug':
logger.debug(msg, exc_info=True, stack_info=True)
elif level == 'error':
logger.error(msg, exc_info=True, stack_info=True)
elif level == 'info':
logger.info(msg, exc_info=True, stack_info=True)
else:
logger.warning(msg, exc_info=True, stack_info=True)
# Check if 'e' is an exception class or instance
if isinstance(e, Exception):
raise e # If 'e' is already an instance of an exception
else:
raise e(msg) # If 'e' is an exception class
class GameException(Exception):
pass
class LineupsMissingException(GameException):
pass
class CardLegalityException(GameException):
pass
class GameNotFoundException(GameException):
pass
class TeamNotFoundException(GameException):
pass
class PlayNotFoundException(GameException):
pass
class PlayInitException(GameException):
pass
class DatabaseError(GameException):
pass