# HG changeset patch # User Goffi # Date 1579283222 -3600 # Node ID 3018d153a61544cf5667b617f1b8400ff2424b84 # Parent 060ac43627fc6d5f5e2a7cd3976e328d9f781f9a quick frontend (widgets): some more errors handling in getOrCreateWidget diff -r 060ac43627fc -r 3018d153a615 sat_frontends/quick_frontend/quick_widgets.py --- a/sat_frontends/quick_frontend/quick_widgets.py Fri Jan 17 17:55:57 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_widgets.py Fri Jan 17 18:47:02 2020 +0100 @@ -255,6 +255,10 @@ if widget is None: raise exceptions.InternalError( "on_existing_widget method must return the widget to use") + if widget not in widgets_map[hash_]: + log.debug( + "the widget returned by on_existing_widget is new, adding it") + widgets_map[hash_].append(widget) else: raise exceptions.InternalError( "Unexpected on_existing_widget value ({})".format(on_existing_widget)) @@ -299,7 +303,11 @@ return widget_hash = str(class_.getWidgetHash(widget_to_delete.target, widget_to_delete.profiles)) - widget_instances = widgets_map[widget_hash] + try: + widget_instances = widgets_map[widget_hash] + except KeyError: + log.error(f"no instance of {class_.__name__} found with hash {widget_hash!r}") + return if all_instances: widget_instances.clear() else: @@ -315,7 +323,7 @@ # all instances with this hash have been deleted # we remove the hash itself del widgets_map[widget_hash] - log.debug("All instances of {cls} with hash {widget_hash} have been deleted" + log.debug("All instances of {cls} with hash {widget_hash!r} have been deleted" .format(cls=class_, widget_hash=widget_hash))