Skip to content

Commit

Permalink
disco: print the name of the plugin if it fails to load (#9719)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzorin committed Jun 16, 2023
1 parent 539d48d commit b1e5efa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions certbot/certbot/_internal/plugins/disco.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@ def find_all(cls) -> 'PluginsRegistry':
pkg_resources.iter_entry_points(
constants.OLD_SETUPTOOLS_PLUGINS_ENTRY_POINT),)
for entry_point in entry_points:
cls._load_entry_point(entry_point, plugins)

try:
cls._load_entry_point(entry_point, plugins)
except Exception as e:
raise errors.PluginError(
f"The '{entry_point.module_name}' plugin errored while loading: {e}. "
"You may need to remove or update this plugin. The Certbot log will "
"contain the full error details and this should be reported to the "
"plugin developer.") from e
return cls(plugins)

@classmethod
Expand Down
11 changes: 11 additions & 0 deletions certbot/certbot/_internal/tests/plugins/disco_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ def test_find_all(self):
assert plugins["ep1"].entry_point is self.ep1
assert "p1:ep1" not in plugins

def test_find_all_error_message(self):
from certbot._internal.plugins.disco import PluginsRegistry
with mock.patch("certbot._internal.plugins.disco.pkg_resources") as mock_pkg:
EP_SA.load = None # This triggers a TypeError when the entrypoint loads
mock_pkg.iter_entry_points.side_effect = [
iter([EP_SA]), iter([EP_WR, self.ep1])
]
with self.assertRaises(errors.PluginError) as cm:
PluginsRegistry.find_all()
assert "standalone' plugin errored" in str(cm.exception)

def test_getitem(self):
assert self.plugin_ep == self.reg["mock"]

Expand Down

0 comments on commit b1e5efa

Please sign in to comment.