mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-05 17:02:32 -05:00
[CogManager, Utils] Handle missing cogs correctly, add some helpful algorithms (#1989)
* Handle missing cogs correctly, add some helpful algorithms For cog loading, only show "cog not found" if the module in question was the one that failed to import. ImportErrors within cogs will show an error as they should. - deduplicator, benchmarked to be the fastest - bounded gather and bounded async as_completed - tests for all additions * Requested changes + wrap as_completed instead So I went source diving and realized as_completed works the way I want it to, and I don't need to reinvent the wheel for cancelling tasks that remain if the generator is `break`ed out of. So there's that.
This commit is contained in:
committed by
Toby Harradine
parent
b550f38eed
commit
1329fa1b09
@@ -77,9 +77,17 @@ class CoreLogic:
|
||||
for name in cog_names:
|
||||
try:
|
||||
spec = await bot.cog_mgr.find_cog(name)
|
||||
cogspecs.append((spec, name))
|
||||
except RuntimeError:
|
||||
notfound_packages.append(name)
|
||||
if spec:
|
||||
cogspecs.append((spec, name))
|
||||
else:
|
||||
notfound_packages.append(name)
|
||||
except Exception as e:
|
||||
log.exception("Package import failed", exc_info=e)
|
||||
|
||||
exception_log = "Exception during import of cog\n"
|
||||
exception_log += "".join(traceback.format_exception(type(e), e, e.__traceback__))
|
||||
bot._last_exception = exception_log
|
||||
failed_packages.append(name)
|
||||
|
||||
for spec, name in cogspecs:
|
||||
try:
|
||||
@@ -95,6 +103,7 @@ class CoreLogic:
|
||||
else:
|
||||
await bot.add_loaded_package(name)
|
||||
loaded_packages.append(name)
|
||||
|
||||
return loaded_packages, failed_packages, notfound_packages
|
||||
|
||||
def _cleanup_and_refresh_modules(self, module_name: str):
|
||||
@@ -511,7 +520,7 @@ class Core(CoreLogic):
|
||||
loaded, failed, not_found = await self._load(cog_names)
|
||||
|
||||
if loaded:
|
||||
fmt = "Loaded {packs}"
|
||||
fmt = "Loaded {packs}."
|
||||
formed = self._get_package_strings(loaded, fmt)
|
||||
await ctx.send(formed)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user