From c6531770b58d9fa87ac007e21e26d6ed1f6f8b30 Mon Sep 17 00:00:00 2001
From: Leif Halldor Asgeirsson <leifur@leifur.ca>
Date: Mon, 14 Nov 2016 21:47:58 -0500
Subject: [PATCH] error handling for my_import

---
 goblin/driver/cluster.py | 11 +++++++++--
 goblin/exception.py      |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/goblin/driver/cluster.py b/goblin/driver/cluster.py
index 5ef5059..b0ca590 100644
--- a/goblin/driver/cluster.py
+++ b/goblin/driver/cluster.py
@@ -32,8 +32,15 @@ from goblin import driver, exception, provider
 
 
 def my_import(name):
-    module_name, class_name = name.rsplit('.', maxsplit=1)
-    module = importlib.import_module(module_name)
+    names = name.rsplit('.', maxsplit=1)
+    if len(names) != 2:
+        raise exception.ConfigError("not a valid absolute python path to a class: {}".format(name))
+    module_name, class_name = names
+    try:
+        module = importlib.import_module(module_name)
+    except ImportError:
+        raise exception.ConfigError(
+                "Error processing cluster configuration: could not import {}".format(name))
     return getattr(module, class_name)
 
 
diff --git a/goblin/exception.py b/goblin/exception.py
index 203102b..46cf2e6 100644
--- a/goblin/exception.py
+++ b/goblin/exception.py
@@ -16,6 +16,10 @@
 # along with Goblin.  If not, see <http://www.gnu.org/licenses/>.
 
 
+class ConfigError(Exception):
+    pass
+
+
 class ClientError(Exception):
     pass
 
-- 
GitLab