From 38df3724718c66ecb42c10def773b9aa0e602ef0 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 7 Jun 2015 17:04:23 -0700 Subject: [PATCH] main.py: catch ImportError nicely --- main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ca32435..4714806 100755 --- a/main.py +++ b/main.py @@ -67,8 +67,14 @@ class Irc(): # Here, we override the module lookup and import the plugins # dynamically depending on which were configured. for plugin in to_load: - moduleinfo = imp.find_module(plugin, plugins_folder) - self.loaded.append(imp.load_source(plugin, moduleinfo[1])) + try: + moduleinfo = imp.find_module(plugin, plugins_folder) + self.loaded.append(imp.load_source(plugin, moduleinfo[1])) + except ImportError as e: + if str(e).startswith('No module named'): + print('Failed to load plugin %r: the plugin could not be found.' % plugin) + else: + print('Failed to load plugin %r: import error %s' (plugin, str(e))) print("loaded plugins: %s" % self.loaded) if __name__ == '__main__':