Skip to content

Commit

Permalink
ENH: Guard for all exceptions in content decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Mar 6, 2017
1 parent 20e5911 commit 0316441
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions kupfer/core/pluginload.py
Expand Up @@ -54,7 +54,7 @@ def load_plugin(plugin_id):
return desc

@contextlib.contextmanager
def exception_guard(name, callback=None, *args):
def exception_guard(name, callback=None, *args, **kwargs):
"Guard for exceptions, print traceback and call @callback if any is raised"
try:
yield
Expand All @@ -65,7 +65,7 @@ def exception_guard(name, callback=None, *args):
pretty.print_error(__name__, "This error is probably a bug in", name)
pretty.print_error(__name__, "Please file a bug report")
if callback is not None:
callback(*args)
callback(*args, **kwargs)

def remove_plugin(plugin_id):
plugins.unimport_plugin(plugin_id)
21 changes: 15 additions & 6 deletions kupfer/core/sources.py
Expand Up @@ -479,8 +479,14 @@ def get_contents_for_leaf(self, leaf, types=None):
for typ in self.content_decorators:
if not isinstance(leaf, typ):
continue
for content in self.content_decorators[typ]:
dsrc = content.decorate_item(leaf)
for content in list(self.content_decorators[typ]):
dsrc = None
with pluginload.exception_guard(
content,
self._remove_source,
content,
is_decorator=True):
dsrc = content.decorate_item(leaf)
if dsrc:
if types and not self.good_source_for_types(dsrc, types):
continue
Expand Down Expand Up @@ -573,11 +579,14 @@ def _try_restore(self, sources):
if source:
yield source

def _remove_source(self, source):
def _remove_source(self, source, is_decorator=False):
"Oust @source from catalog if any exception is raised"
self.sources.discard(source)
self.toplevel_sources.discard(source)
source_type = type(source)
if not is_decorator:
self.sources.discard(source)
self.toplevel_sources.discard(source)
source_type = type(source)
else:
source_type = source
for typ in self.content_decorators:
self.content_decorators[typ].discard(source_type)

Expand Down

0 comments on commit 0316441

Please sign in to comment.