From c033e5111fd6b0f8f1870ce7a450f47bf459bad6 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 16 Feb 2017 14:57:05 -0800 Subject: [PATCH] Graceful error message for abstract base classes in PluginLoader --- lib/ansible/plugins/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py index 8962c252dc..5d836bb272 100644 --- a/lib/ansible/plugins/__init__.py +++ b/lib/ansible/plugins/__init__.py @@ -31,7 +31,6 @@ import warnings from collections import defaultdict from ansible import constants as C -from ansible.compat.six import string_types 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, found_in_cache=found_in_cache, class_only=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 @@ -430,7 +436,10 @@ class PluginLoader: self._display_plugin_load(self.class_name, name, self._searched_paths, path, found_in_cache=found_in_cache, class_only=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 setattr(obj, '_original_path', path)