Skip to content

Commit

Permalink
Error-handle a timeout error when loading plugins (#3330)
Browse files Browse the repository at this point in the history
* Fix registry loading errors

* Fix black formatting

* Repo consistency

* Change code cleanness as requested by taku

---------

Co-authored-by: Taku <45324516+Taaku18@users.noreply.github.com>
  • Loading branch information
sebkuip and Taaku18 authored Oct 27, 2024
1 parent 5de513c commit 3c422c8
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cogs/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
import sys
import typing
import zipfile
from importlib import invalidate_caches
from difflib import get_close_matches
from importlib import invalidate_caches
from pathlib import Path, PurePath
from re import match
from site import USER_SITE
from subprocess import PIPE

import discord
from discord.ext import commands

from packaging.version import Version

from core import checks
from core.models import PermissionLevel, getLogger
from core.paginator import EmbedPaginatorSession
from core.utils import truncate, trigger_typing
from core.utils import trigger_typing, truncate

logger = getLogger(__name__)

Expand Down Expand Up @@ -132,8 +131,11 @@ async def cog_load(self):

async def populate_registry(self):
url = "https://raw.githubusercontent.com/modmail-dev/modmail/master/plugins/registry.json"
async with self.bot.session.get(url) as resp:
self.registry = json.loads(await resp.text())
try:
async with self.bot.session.get(url) as resp:
self.registry = json.loads(await resp.text())
except asyncio.TimeoutError:
logger.warning("Failed to fetch registry. Loading with empty registry")

async def initial_load_plugins(self):
for plugin_name in list(self.bot.config["plugins"]):
Expand Down Expand Up @@ -638,6 +640,14 @@ async def plugins_registry(self, ctx, *, plugin_name: typing.Union[int, str] = N

registry = sorted(self.registry.items(), key=lambda elem: elem[0])

if not registry:
embed = discord.Embed(
color=self.bot.error_color,
description="Registry is empty. This could be because it failed to load.",
)
await ctx.send(embed=embed)
return

if isinstance(plugin_name, int):
index = plugin_name - 1
if index < 0:
Expand Down

0 comments on commit 3c422c8

Please sign in to comment.