disco: print the name of the plugin if it fails to load (#9719)

This commit is contained in:
alexzorin 2023-06-17 01:26:15 +10:00 committed by GitHub
parent 539d48d438
commit b1e5efac3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -189,8 +189,14 @@ class PluginsRegistry(Mapping):
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

View file

@ -194,6 +194,17 @@ class PluginsRegistryTest(unittest.TestCase):
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"]