Skip to content

Commit 3c422c8

Browse files
sebkuipTaaku18
andauthored
Error-handle a timeout error when loading plugins (#3330)
* Fix registry loading errors * Fix black formatting * Repo consistency * Change code cleanness as requested by taku --------- Co-authored-by: Taku <[email protected]>
1 parent 5de513c commit 3c422c8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

cogs/plugins.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66
import sys
77
import typing
88
import zipfile
9-
from importlib import invalidate_caches
109
from difflib import get_close_matches
10+
from importlib import invalidate_caches
1111
from pathlib import Path, PurePath
1212
from re import match
1313
from site import USER_SITE
1414
from subprocess import PIPE
1515

1616
import discord
1717
from discord.ext import commands
18-
1918
from packaging.version import Version
2019

2120
from core import checks
2221
from core.models import PermissionLevel, getLogger
2322
from core.paginator import EmbedPaginatorSession
24-
from core.utils import truncate, trigger_typing
23+
from core.utils import trigger_typing, truncate
2524

2625
logger = getLogger(__name__)
2726

@@ -132,8 +131,11 @@ async def cog_load(self):
132131

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

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

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

643+
if not registry:
644+
embed = discord.Embed(
645+
color=self.bot.error_color,
646+
description="Registry is empty. This could be because it failed to load.",
647+
)
648+
await ctx.send(embed=embed)
649+
return
650+
641651
if isinstance(plugin_name, int):
642652
index = plugin_name - 1
643653
if index < 0:

0 commit comments

Comments
 (0)