mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Graceful error message for abstract base classes in PluginLoader
This commit is contained in:
parent
374af06cbf
commit
c033e5111f
1 changed files with 12 additions and 3 deletions
|
@ -31,7 +31,6 @@ import warnings
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.compat.six import string_types
|
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,7 +369,14 @@ class PluginLoader:
|
||||||
self._display_plugin_load(self.class_name, name, self._searched_paths, path,
|
self._display_plugin_load(self.class_name, name, self._searched_paths, path,
|
||||||
found_in_cache=found_in_cache, class_only=class_only)
|
found_in_cache=found_in_cache, class_only=class_only)
|
||||||
if not class_only:
|
if not class_only:
|
||||||
obj = obj(*args, **kwargs)
|
try:
|
||||||
|
obj = obj(*args, **kwargs)
|
||||||
|
except TypeError as e:
|
||||||
|
if "abstract" in e.args[0]:
|
||||||
|
# Abstract Base Class. The found plugin file does not
|
||||||
|
# fully implement the defined interface.
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@ -430,7 +436,10 @@ class PluginLoader:
|
||||||
self._display_plugin_load(self.class_name, name, self._searched_paths, path,
|
self._display_plugin_load(self.class_name, name, self._searched_paths, path,
|
||||||
found_in_cache=found_in_cache, class_only=class_only)
|
found_in_cache=found_in_cache, class_only=class_only)
|
||||||
if not class_only:
|
if not class_only:
|
||||||
obj = obj(*args, **kwargs)
|
try:
|
||||||
|
obj = obj(*args, **kwargs)
|
||||||
|
except TypeError as e:
|
||||||
|
display.warning("Skipping plugin (%s) as it seems to be incomplete: %s" % (path, to_text(e)))
|
||||||
|
|
||||||
# set extra info on the module, in case we want it later
|
# set extra info on the module, in case we want it later
|
||||||
setattr(obj, '_original_path', path)
|
setattr(obj, '_original_path', path)
|
||||||
|
|
Loading…
Reference in a new issue