sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
948 stars 402 forks source link

`sopel-plugins list` crashes for malformed plugin #2618

Open SnoopJ opened 2 months ago

SnoopJ commented 2 months ago

Description

A plugin that causes an exception at load time will cause sopel-plugins list to crash when listing plugins.

Reproduction steps

  1. Install a malformed plugin that causes an exception on load
  2. Run sopel-plugins list and observe the crash
click for reproduction commands and detailed traceback ``` $ .sopel/venv/bin/python3 -m pip install --force-reinstall git+ssh://git@github.com/SnoopJ/sopel-wasi-cpython.git@d953130363e322b10457c6df5f8306e9c5e24282 ... $ .sopel/venv/bin/sopel-plugins list -c ~/.sopel/terribot.cfg 8ball/python-file 8ball plugin (/home/snoopjedi/repos/galois/8ball.py) [enabled] acr/python-file acr plugin (/home/snoopjedi/repos/galois/acr.py) [enabled] admin/python-module admin.py - Sopel Admin Plugin (sopel.builtins.admin) [enabled] adminchannel/python-module adminchannel.py - Sopel Channel Admin Plugin (sopel.builtins.adminchannel) [disabled] ... and so on until the offending plugin... Traceback (most recent call last): File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/cli/plugins.py", line 204, in handle_list plugin.load() File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/plugins/handlers.py", line 604, in load self._module = self.entry_point.load() File "/home/snoopjedi/.sopel/venv/lib/python3.9/site-packages/importlib_metadata/__init__.py", line 209, in load module = import_module(match.group('module')) File "/home/snoopjedi/.pyenv/versions/3.9.16/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File "/home/snoopjedi/.sopel/venv/lib/python3.9/site-packages/sopel_wasi_cpython/__init__.py", line 9, in from .run import run_python ModuleNotFoundError: No module named 'sopel_wasi_cpython.run' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/snoopjedi/.sopel/venv/bin/sopel-plugins", line 8, in sys.exit(main()) File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/cli/plugins.py", line 555, in main return handle_list(options) File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/cli/plugins.py", line 214, in handle_list description.update(plugin.get_meta_description()) File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/plugins/handlers.py", line 647, in get_meta_description data = super().get_meta_description() File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/plugins/handlers.py", line 321, in get_meta_description 'version': self.get_version(), File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/plugins/handlers.py", line 616, in get_version and hasattr(self.module, "__package__") File "/home/snoopjedi/.sopel/sopel-src-terribot.git/sopel/plugins/handlers.py", line 275, in module raise RuntimeError('No module for plugin %s' % self.name) RuntimeError: No module for plugin wasi-cpython ```

Expected behavior

I would expect sopel-plugins list to report that the plugin is known (because of its entrypoint) but is malformed and cannot be loaded, without crashing the command.

Relevant logs

N/A

Notes

Discovered while @dgw had a go at the sopel-wasi-cpython plugin I've been developing

Sopel version

8.0.0

Installation method

pip install

Python version

3.9.16 (also observed on 3.12)

Operating system

Ubuntu 22.04

IRCd

N/A

Relevant plugins

N/A