mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
capture attribute errors for invalid class plugins
also switched to py3 safe to_str
This commit is contained in:
parent
fd9838f1a0
commit
5225048df9
1 changed files with 8 additions and 3 deletions
|
@ -31,6 +31,7 @@ import warnings
|
|||
from collections import defaultdict
|
||||
|
||||
from ansible import constants as C
|
||||
from ansible.utils.unicode import to_str
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
|
@ -247,7 +248,7 @@ class PluginLoader:
|
|||
try:
|
||||
full_paths = (os.path.join(path, f) for f in os.listdir(path))
|
||||
except OSError as e:
|
||||
display.warning("Error accessing plugin paths: %s" % str(e))
|
||||
display.warning("Error accessing plugin paths: %s" % to_str(e))
|
||||
|
||||
for full_path in (f for f in full_paths if os.path.isfile(f) and not f.endswith('__init__.py')):
|
||||
full_name = os.path.basename(full_path)
|
||||
|
@ -366,7 +367,11 @@ class PluginLoader:
|
|||
if path not in self._module_cache:
|
||||
self._module_cache[path] = self._load_module_source(name, path)
|
||||
|
||||
obj = getattr(self._module_cache[path], self.class_name)
|
||||
try:
|
||||
obj = getattr(self._module_cache[path], self.class_name)
|
||||
except AttributeError as e:
|
||||
display.warning("Skipping plugin (%s) as it seems to be invalid: %s" % (path, to_str(e)))
|
||||
|
||||
if self.base_class:
|
||||
# The import path is hardcoded and should be the right place,
|
||||
# so we are not expecting an ImportError.
|
||||
|
|
Loading…
Reference in a new issue