diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-25 18:07:49 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2014-09-25 18:07:49 +0200 |
| commit | cb298967db1f9ad69d4b5c198c64d82fa770fccb (patch) | |
| tree | e33d681094591f1130d42dc2b1837da217f39cf8 /client | |
| parent | ea3026c133755bf3e35ad78fa253786bc9ff7c36 (diff) | |
| download | jasper-client-cb298967db1f9ad69d4b5c198c64d82fa770fccb.tar.gz jasper-client-cb298967db1f9ad69d4b5c198c64d82fa770fccb.zip | |
Catch errors in client modules and warn users about them instead of crashing the whole application
Diffstat (limited to 'client')
| -rw-r--r-- | client/brain.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/client/brain.py b/client/brain.py index f2a2efd..1ed6db5 100644 --- a/client/brain.py +++ b/client/brain.py @@ -32,13 +32,22 @@ class Brain(object): module, a priority of 0 is assumed. """ + logger = logging.getLogger(__name__) module_locations = [jasperpath.PLUGIN_PATH] + logger.debug("Looking for modules in: %s", ', '.join(["'%s'" % location for location in module_locations])) module_names = [name for loader, name, ispkg in pkgutil.walk_packages(module_locations, prefix='modules.')] modules = [] for name in module_names: - mod = importlib.import_module(name) - if hasattr(mod, 'WORDS'): - modules.append(mod) + try: + mod = importlib.import_module(name) + except: + logger.warning("Skipped module '%s' due to an error.", name, exc_info=True) + else: + if hasattr(mod, 'WORDS'): + logger.debug("Found module '%s' with words: %r", name, mod.WORDS) + modules.append(mod) + else: + logger.warning("Skipped module '%s' because it misses the WORDS constant.", name) modules.sort(key=lambda mod: mod.PRIORITY if hasattr(mod, 'PRIORITY') else 0, reverse=True) return modules |
