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

Fix bug with ?plugin update. #3295

Merged
merged 1 commit into from
Nov 19, 2023

Conversation

Jerrie-Aries
Copy link
Contributor

This PR fixes bug occured when running ?plugin update command and only if the updated plugin is broken.

@Jerrie-Aries
Copy link
Contributor Author

Jerrie-Aries commented Jul 22, 2023

Traceback:

Traceback (most recent call last):
  File "/User/Projects/modmail/cogs/plugins.py", line 259, in load_plugin
    await self.bot.load_extension(plugin.ext_string)
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 1012, in load_extension
    await self._load_from_module_spec(spec, name)
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 937, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'plugins.@local.supportutils.supportutils' raised an error: SyntaxError: invalid syntax (supportutils.py, line 22)
2023-07-22 14:55:42 __main__[1531] - ERROR: Unexpected exception:
Traceback (most recent call last):
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 934, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 846, in exec_module
  File "<frozen importlib._bootstrap_external>", line 983, in get_code
  File "<frozen importlib._bootstrap_external>", line 913, in source_to_code
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/User/Projects/modmail/plugins/@local/supportutils/supportutils.py", line 22
    .
    ^
SyntaxError: invalid syntax

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/User/Projects/modmail/cogs/plugins.py", line 259, in load_plugin
    await self.bot.load_extension(plugin.ext_string)
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 1012, in load_extension
    await self._load_from_module_spec(spec, name)
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 937, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'plugins.@local.supportutils.supportutils' raised an error: SyntaxError: invalid syntax (supportutils.py, line 22)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/User/Projects/modmail/cogs/plugins.py", line 499, in update_plugin
    await self.load_plugin(plugin)
  File "/User/Projects/modmail/cogs/plugins.py", line 265, in load_plugin
    raise InvalidPluginError("Cannot load extension, plugin invalid.") from exc
cogs.plugins.InvalidPluginError: Cannot load extension, plugin invalid.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/core.py", line 190, in wrapped
    ret = await coro(*args, **kwargs)
  File "/User/Projects/modmail/cogs/plugins.py", line 530, in plugins_update
    await self.update_plugin(ctx, plugin_name)
  File "/User/Projects/modmail/cogs/plugins.py", line 505, in update_plugin
    self.bot.config["plugins"].remove(plugin_name)
ValueError: list.remove(x): x not in list

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 1347, in invoke
    await ctx.command.invoke(ctx)
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/core.py", line 1605, in invoke
    await ctx.invoked_subcommand.invoke(ctx)
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/core.py", line 986, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "/User/Projects/modmail/.venv/lib/python3.9/site-packages/discord/ext/commands/core.py", line 199, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ValueError: list.remove(x): x not in list

This occured when I used command ?plugin update local/supportutils. And the plugin file had a syntax error.

This is the part that we want to solve:

self.bot.config["plugins"].remove(plugin_name)
ValueError: list.remove(x): x not in list

Because of this error, the bot fails to remove the plugin from config.

@Taaku18 Taaku18 added the staged Staged for next version label Nov 19, 2023
Copy link
Collaborator

@Taaku18 Taaku18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be implemented for the next update, thanks!

@Taaku18 Taaku18 merged commit a94e7a9 into modmail-dev:development Nov 19, 2023
@Jerrie-Aries Jerrie-Aries deleted the dev-patch-1 branch November 19, 2023 23:31
@Taaku18 Taaku18 mentioned this pull request Nov 20, 2023
raidensakura pushed a commit to raidensakura/modmail that referenced this pull request Apr 10, 2024
khakers pushed a commit to khakers/OpenModmail that referenced this pull request Jun 18, 2024
(cherry picked from commit a94e7a9)
Signed-off-by: Khakers <22665282+khakers@users.noreply.github.com>
khakers pushed a commit to khakers/OpenModmail that referenced this pull request Jun 18, 2024
(cherry picked from commit a94e7a9)
Signed-off-by: Khakers <22665282+khakers@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
staged Staged for next version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants