Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ async def start_bot(bot: custom.Bot, token: str) -> None:
except LoginFailure as e:
logger.critical("Failed to log in, is the bot token valid?")
logger.debug("", exc_info=e)
except Exception as e: # noqa: BLE001
logger.critical("An unexpected error occurred while starting the bot.")
logger.debug("", exc_info=e)


async def start_backend(app: Quart, bot: discord.Bot, token: str) -> None:
Expand Down Expand Up @@ -64,9 +67,13 @@ def __init__(
app_config.logger_class = CustomLogger
app_config.include_server_header = False # security
app_config.bind = ["0.0.0.0:5000"]
await bot.login(token)
await serve(app, app_config)
patch("hypercorn.error")
try:
await bot.login(token)
await serve(app, app_config)
patch("hypercorn.error")
except Exception as e: # noqa: BLE001
logger.critical("An error occurred while starting the backend server.")
logger.debug("", exc_info=e)


def load_extensions() -> (
Expand Down Expand Up @@ -94,7 +101,12 @@ def load_extensions() -> (
continue

its_config = config["extensions"].get(name, config["extensions"].get(name.replace("_", "-"), {}))
module: ModuleType = importlib.import_module(f"src.extensions.{name}")
try:
module: ModuleType = importlib.import_module(f"src.extensions.{name}")
except ImportError as e:
logger.error(f"Failed to import extension {name}")
logger.debug("", exc_info=e)
continue
if not its_config:
its_config = module.default
config["extensions"][name] = its_config
Expand Down
Loading