Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure bot doesn't indefinitely hang on an exception in on_ready #6202

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
21 changes: 14 additions & 7 deletions redbot/core/_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from packaging.requirements import Requirement
from redbot.core import data_manager

from redbot.core.bot import ExitCodes
from redbot.core.commands import RedHelpFormatter, HelpSettings
from redbot.core.i18n import (
Translator,
Expand Down Expand Up @@ -140,6 +141,13 @@ async def on_connect():

@bot.event
async def on_ready():
try:
await _on_ready()
except Exception as exc:
log.critical("The bot failed to get ready!", exc_info=exc)
sys.exit(ExitCodes.CRITICAL)

async def _on_ready():
if bot._uptime is not None:
return

Expand Down Expand Up @@ -170,13 +178,12 @@ async def on_ready():

outdated_red_message = ""
rich_outdated_message = ""
with contextlib.suppress(aiohttp.ClientError, asyncio.TimeoutError):
pypi_version, py_version_req = await fetch_latest_red_version_info()
outdated = pypi_version and pypi_version > red_version_info
if outdated:
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
pypi_version, py_version_req
)
pypi_version, py_version_req = await fetch_latest_red_version_info()
outdated = pypi_version and pypi_version > red_version_info
if outdated:
outdated_red_message, rich_outdated_message = get_outdated_red_messages(
pypi_version, py_version_req
)

rich_console = rich.get_console()
rich_console.print(INTRO, style="red", markup=False, highlight=False)
Expand Down