From f835e84d80cfbe67555def79228d8dc27d6e5c6a Mon Sep 17 00:00:00 2001 From: croneter Date: Tue, 20 Nov 2018 18:57:54 +0100 Subject: [PATCH] Fix context managers swallowing exceptions --- resources/lib/itemtypes/common.py | 3 +++ resources/lib/kodi_db/common.py | 3 +++ resources/lib/plex_db/common.py | 3 +++ resources/lib/utils.py | 3 ++- resources/lib/windows/kodigui.py | 6 ++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/resources/lib/itemtypes/common.py b/resources/lib/itemtypes/common.py index 0bead0d2..f2db7b27 100644 --- a/resources/lib/itemtypes/common.py +++ b/resources/lib/itemtypes/common.py @@ -70,6 +70,9 @@ class ItemBase(object): """ Make sure DB changes are committed and connection to DB is closed. """ + if exc_type: + # re-raise any exception + return False self.commit() self.plexconn.close() self.kodiconn.close() diff --git a/resources/lib/kodi_db/common.py b/resources/lib/kodi_db/common.py index 52042150..7ffe8d09 100644 --- a/resources/lib/kodi_db/common.py +++ b/resources/lib/kodi_db/common.py @@ -27,6 +27,9 @@ class KodiDBBase(object): return self def __exit__(self, e_typ, e_val, trcbak): + if e_typ: + # re-raise any exception + return False self.kodiconn.commit() self.kodiconn.close() if self._texture_db: diff --git a/resources/lib/plex_db/common.py b/resources/lib/plex_db/common.py index b7b254f8..e1338988 100644 --- a/resources/lib/plex_db/common.py +++ b/resources/lib/plex_db/common.py @@ -29,6 +29,9 @@ class PlexDBBase(object): return self def __exit__(self, e_typ, e_val, trcbak): + if e_typ: + # re-raise any exception + return False self.plexconn.commit() self.plexconn.close() diff --git a/resources/lib/utils.py b/resources/lib/utils.py index c5cf11dd..740d0eb2 100644 --- a/resources/lib/utils.py +++ b/resources/lib/utils.py @@ -667,7 +667,8 @@ class XmlKodiSetting(object): def __exit__(self, e_typ, e_val, trcbak): if e_typ: - raise + # re-raise any exception + return False # Only safe to file if we did not botch anything if self.write_xml is True: self._remove_empty_elements() diff --git a/resources/lib/windows/kodigui.py b/resources/lib/windows/kodigui.py index 08dc795c..9bd917e7 100644 --- a/resources/lib/windows/kodigui.py +++ b/resources/lib/windows/kodigui.py @@ -986,6 +986,9 @@ class WindowProperty(): return self def __exit__(self, exc_type, exc_value, traceback): + if exc_type: + # re-raise any exception + return False self.win.setProperty(self.prop, self.end or self.old) @@ -1003,4 +1006,7 @@ class GlobalProperty(): return self def __exit__(self, exc_type, exc_value, traceback): + if exc_type: + # re-raise any exception + return False xbmcgui.Window(10000).setProperty('{0}.{1}'.format(self._addonID, self.prop), self.end or self.old)