[PATCH] [WOK] Github #745: Making import error messages less useless

From: Daniel Henrique Barboza <dhbarboza82@gmail.com> Title says it all. This is an experiment I've made by removing the package 'python-magic' and then trying to boot WoK: Failed to import plugin plugins.kimchi.KimchiRoot Failed to import plugin plugins.ginger.Ginger Today, there's absolutely no info of what happened. With this fix we'll get: Failed to import plugin plugins.kimchi.KimchiRoot, error: Class plugins.kimchi.KimchiRoot can not be imported, error: No module named magic Failed to import plugin plugins.ginger.Ginger, error: Class plugins.ginger.Ginger can not be imported, error: No module named magic And then we can install the missing dependency right away. Daniel Henrique Barboza (1): Github #745: WoK: improve error message when importing plug-ins src/wok/server.py | 17 ++++++++++------- src/wok/utils.py | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) -- 2.4.3

From: Daniel Henrique Barboza <dhbarboza82@gmail.com> Error messages in WoK boot-up process weren't being forwarded to the user, making it harder to detect the cause of the failure. Signed-off-by: Daniel Henrique Barboza <dhbarboza82@gmail.com> --- src/wok/server.py | 17 ++++++++++------- src/wok/utils.py | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/wok/server.py b/src/wok/server.py index c6f12dd..59ecdc0 100644 --- a/src/wok/server.py +++ b/src/wok/server.py @@ -158,9 +158,11 @@ class Server(object): try: plugin_app = import_class(plugin_class)(options) - except ImportError: - cherrypy.log.error_log.error("Failed to import plugin %s" % - plugin_class) + except ImportError, e: + cherrypy.log.error_log.error( + "Failed to import plugin %s, " + "error: %s" % (plugin_class, e.message) + ) continue # dynamically extend plugin config with custom data, if provided @@ -173,10 +175,11 @@ class Server(object): try: authed_apis = import_class(('plugins.%s.%s' % (plugin_name, extra_auth))) - except ImportError: - cherrypy.log.error_log.error("Failed to import subnodes " - "for plugin %s" % - plugin_class) + except ImportError, e: + cherrypy.log.error_log.error( + "Failed to import subnodes for plugin %s, " + "error: %s" % (plugin_class, e.message) + ) continue urlSubNodes = {} diff --git a/src/wok/utils.py b/src/wok/utils.py index ccc8534..74c521f 100644 --- a/src/wok/utils.py +++ b/src/wok/utils.py @@ -114,8 +114,11 @@ def import_class(class_path): try: mod = import_module(module_name, class_name) return getattr(mod, class_name) - except (ImportError, AttributeError): - raise ImportError('Class %s can not be imported' % class_path) + except (ImportError, AttributeError), e: + raise ImportError( + 'Class %s can not be imported, ' + 'error: %s' % (class_path, e.message) + ) def import_module(module_name, class_name=''): -- 2.4.3

Good and required one. Reviewed-by: Chandra Shekhar Reddy Potula <chandra@linux.vnet.ibm.com> On 10/30/2015 02:18 AM, dhbarboza82@gmail.com wrote:
From: Daniel Henrique Barboza <dhbarboza82@gmail.com>
Error messages in WoK boot-up process weren't being forwarded to the user, making it harder to detect the cause of the failure.
Signed-off-by: Daniel Henrique Barboza <dhbarboza82@gmail.com> --- src/wok/server.py | 17 ++++++++++------- src/wok/utils.py | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/wok/server.py b/src/wok/server.py index c6f12dd..59ecdc0 100644 --- a/src/wok/server.py +++ b/src/wok/server.py @@ -158,9 +158,11 @@ class Server(object):
try: plugin_app = import_class(plugin_class)(options) - except ImportError: - cherrypy.log.error_log.error("Failed to import plugin %s" % - plugin_class) + except ImportError, e: + cherrypy.log.error_log.error( + "Failed to import plugin %s, " + "error: %s" % (plugin_class, e.message) + ) continue
# dynamically extend plugin config with custom data, if provided @@ -173,10 +175,11 @@ class Server(object): try: authed_apis = import_class(('plugins.%s.%s' % (plugin_name, extra_auth))) - except ImportError: - cherrypy.log.error_log.error("Failed to import subnodes " - "for plugin %s" % - plugin_class) + except ImportError, e: + cherrypy.log.error_log.error( + "Failed to import subnodes for plugin %s, " + "error: %s" % (plugin_class, e.message) + ) continue
urlSubNodes = {} diff --git a/src/wok/utils.py b/src/wok/utils.py index ccc8534..74c521f 100644 --- a/src/wok/utils.py +++ b/src/wok/utils.py @@ -114,8 +114,11 @@ def import_class(class_path): try: mod = import_module(module_name, class_name) return getattr(mod, class_name) - except (ImportError, AttributeError): - raise ImportError('Class %s can not be imported' % class_path) + except (ImportError, AttributeError), e: + raise ImportError( + 'Class %s can not be imported, ' + 'error: %s' % (class_path, e.message) + )
def import_module(module_name, class_name=''):

On Thu, 2015-10-29 at 18:48 -0200, dhbarboza82@gmail.com wrote:
From: Daniel Henrique Barboza <dhbarboza82@gmail.com>
Error messages in WoK boot-up process weren't being forwarded to the user, making it harder to detect the cause of the failure.
Signed-off-by: Daniel Henrique Barboza <dhbarboza82@gmail.com> --- src/wok/server.py | 17 ++++++++++------- src/wok/utils.py | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/wok/server.py b/src/wok/server.py index c6f12dd..59ecdc0 100644 --- a/src/wok/server.py +++ b/src/wok/server.py @@ -158,9 +158,11 @@ class Server(object):
try: plugin_app = import_class(plugin_class)(options) - except ImportError: - cherrypy.log.error_log.error("Failed to import plugin %s" % - plugin_class) + except ImportError, e: + cherrypy.log.error_log.error( + "Failed to import plugin %s, " + "error: %s" % (plugin_class, e.message) + ) continue
# dynamically extend plugin config with custom data, if provided @@ -173,10 +175,11 @@ class Server(object): try: authed_apis = import_class(('plugins.%s.%s' % (plugin_name, extra_auth))) - except ImportError: - cherrypy.log.error_log.error("Failed to import subnodes " - "for plugin %s" % - plugin_class) + except ImportError, e: + cherrypy.log.error_log.error( + "Failed to import subnodes for plugin %s, " + "error: %s" % (plugin_class, e.message) + )
+1 Much needed change.
continue
urlSubNodes = {} diff --git a/src/wok/utils.py b/src/wok/utils.py index ccc8534..74c521f 100644 --- a/src/wok/utils.py +++ b/src/wok/utils.py @@ -114,8 +114,11 @@ def import_class(class_path): try: mod = import_module(module_name, class_name) return getattr(mod, class_name) - except (ImportError, AttributeError): - raise ImportError('Class %s can not be imported' % class_path) + except (ImportError, AttributeError), e: + raise ImportError( + 'Class %s can not be imported, ' + 'error: %s' % (class_path, e.message) + )
def import_module(module_name, class_name=''):

Good and required one. Reviewed-by: Chandra Shekhar Reddy Potula <chandra@linux.vnet.ibm.com> On 10/30/2015 02:18 AM, dhbarboza82@gmail.com wrote:
From: Daniel Henrique Barboza <dhbarboza82@gmail.com>
Title says it all.
This is an experiment I've made by removing the package 'python-magic' and then trying to boot WoK:
Failed to import plugin plugins.kimchi.KimchiRoot Failed to import plugin plugins.ginger.Ginger
Today, there's absolutely no info of what happened. With this fix we'll get:
Failed to import plugin plugins.kimchi.KimchiRoot, error: Class plugins.kimchi.KimchiRoot can not be imported, error: No module named magic Failed to import plugin plugins.ginger.Ginger, error: Class plugins.ginger.Ginger can not be imported, error: No module named magic
And then we can install the missing dependency right away.
Daniel Henrique Barboza (1): Github #745: WoK: improve error message when importing plug-ins
src/wok/server.py | 17 ++++++++++------- src/wok/utils.py | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-)

Applied. Thanks. Regards, Aline Manera
participants (4)
-
Abhiram
-
Aline Manera
-
Chandra Shehkhar Reddy Potula
-
dhbarboza82@gmail.com