From 5782e7b2577abef15102376a0a4e008dbb9b1e19 Mon Sep 17 00:00:00 2001 From: MoojMidge <56883549+MoojMidge@users.noreply.github.com> Date: Wed, 3 Apr 2024 03:33:07 +1100 Subject: [PATCH] Tidy up some exception catching --- .../youtube_plugin/kodion/context/xbmc/xbmc_context.py | 4 ++-- resources/lib/youtube_plugin/kodion/utils/methods.py | 10 ++++++++-- .../lib/youtube_plugin/kodion/utils/system_version.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py index 45bd5d7ff..830560aed 100644 --- a/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py +++ b/resources/lib/youtube_plugin/kodion/context/xbmc/xbmc_context.py @@ -534,7 +534,7 @@ def addon_enabled(self, addon_id): 'properties': ['enabled']}) try: return response['result']['addon']['enabled'] is True - except KeyError: + except (KeyError, TypeError): error = response.get('error', {}) self.log_error('XbmcContext.addon_enabled error - |{0}: {1}|' .format(error.get('code', 'unknown'), @@ -547,7 +547,7 @@ def set_addon_enabled(self, addon_id, enabled=True): 'enabled': enabled}) try: return response['result'] == 'OK' - except KeyError: + except (KeyError, TypeError): error = response.get('error', {}) self.log_error('XbmcContext.set_addon_enabled error - |{0}: {1}|' .format(error.get('code', 'unknown'), diff --git a/resources/lib/youtube_plugin/kodion/utils/methods.py b/resources/lib/youtube_plugin/kodion/utils/methods.py index 6f5c35b68..7aa51eeb8 100644 --- a/resources/lib/youtube_plugin/kodion/utils/methods.py +++ b/resources/lib/youtube_plugin/kodion/utils/methods.py @@ -323,10 +323,16 @@ def merge_dicts(item1, item2, templates=None, _=Ellipsis): return new or _ -def get_kodi_setting_value(setting): +def get_kodi_setting_value(setting, process=None): response = jsonrpc(method='Settings.GetSettingValue', params={'setting': setting}) - return response.get('result', {}).get('value') + try: + value = response['result']['value'] + if process: + return process(value) + except (KeyError, TypeError, ValueError): + return None + return value def get_kodi_setting_bool(setting): diff --git a/resources/lib/youtube_plugin/kodion/utils/system_version.py b/resources/lib/youtube_plugin/kodion/utils/system_version.py index 67a24f120..de4f500f1 100644 --- a/resources/lib/youtube_plugin/kodion/utils/system_version.py +++ b/resources/lib/youtube_plugin/kodion/utils/system_version.py @@ -38,7 +38,7 @@ def __init__(self, version=None, releasename=None, appname=None): self._version = (version_installed.get('major', 1), version_installed.get('minor', 0)) self._appname = response['result']['name'] - except: + except (KeyError, TypeError): self._version = (1, 0) # Frodo self._appname = 'Unknown Application'