From 615e541513a4b2b1c690e228537c62514b86293a Mon Sep 17 00:00:00 2001 From: shaun Date: Tue, 22 Nov 2016 23:05:16 +1100 Subject: [PATCH] remove the internal_exception.ExceptionWrapper class --- default.py | 11 ++++------ resources/lib/downloadutils.py | 32 +++++++++++++++++++--------- resources/lib/ga_client.py | 13 ++++------- resources/lib/internal_exceptions.py | 5 ----- resources/lib/librarysync.py | 3 +-- resources/lib/objects/_common.py | 9 +++----- resources/lib/service_entry.py | 5 +++-- service.py | 12 ++++------- 8 files changed, 41 insertions(+), 49 deletions(-) delete mode 100644 resources/lib/internal_exceptions.py diff --git a/default.py b/default.py index 0116b498..87237518 100644 --- a/default.py +++ b/default.py @@ -24,7 +24,6 @@ import loghandler from utils import window, dialog, language as lang from ga_client import GoogleAnalytics import database -import internal_exceptions ################################################################################################# @@ -162,13 +161,11 @@ if __name__ == "__main__": try: Main() - except internal_exceptions.ExceptionWrapper as error: - log.exception(error) - raise except Exception as error: - ga = GoogleAnalytics() - errStrings = ga.formatException() - ga.sendEventData("Exception", errStrings[0], errStrings[1]) + if not (hasattr(error, 'quiet') and error.quiet): + ga = GoogleAnalytics() + errStrings = ga.formatException() + ga.sendEventData("Exception", errStrings[0], errStrings[1]) log.exception(error) raise diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 4cfaf841..7c23b5ab 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -11,7 +11,6 @@ import xbmcgui import clientinfo import connect.connectionmanager as connectionmanager from utils import window, settings, language as lang -import internal_exceptions ################################################################################################## @@ -231,7 +230,9 @@ class DownloadUtils(object): # does the URL look ok if url.startswith('/'): - raise internal_exceptions.ExceptionWrapper("URL Error: " + url) + exc = Exception("URL Error: " + url) + exc.quiet = True + raise exc ##### PREPARE REQUEST ##### kwargs.update({ @@ -272,28 +273,33 @@ class DownloadUtils(object): except requests.exceptions.SSLError as error: log.error("invalid SSL certificate for: %s", url) - raise internal_exceptions.ExceptionWrapper(error) + error.quiet = True + raise except requests.exceptions.ConnectTimeout as error: log.error("ConnectTimeout at: %s", url) - raise internal_exceptions.ExceptionWrapper(error) + error.quiet = True + raise except requests.exceptions.ReadTimeout as error: log.error("ReadTimeout at: %s", url) - raise internal_exceptions.ExceptionWrapper(error) + error.quiet = True + raise except requests.exceptions.ConnectionError as error: # Make the addon aware of status if window('emby_online') != "false": log.error("Server unreachable at: %s", url) window('emby_online', value="false") - raise internal_exceptions.ExceptionWrapper(error) + error.quiet = True + raise except requests.exceptions.HTTPError as error: if response.status_code == 400: log.error("Malformed request: %s", error) - raise internal_exceptions.ExceptionWrapper(error) + error.quiet = True + raise if response.status_code == 401: # Unauthorized @@ -309,12 +315,16 @@ class DownloadUtils(object): icon=xbmcgui.NOTIFICATION_ERROR, time=5000) window('emby_serverStatus', value="restricted") - raise internal_exceptions.ExceptionWrapper("restricted: " + str(error)) + exc = Exception("restricted: " + str(error)) + exc.quiet = True + raise exc elif (response.headers['X-Application-Error-Code'] == "UnauthorizedAccessException"): # User tried to do something his emby account doesn't allow - raise internal_exceptions.ExceptionWrapper("UnauthorizedAccessException: " + str(error)) + exc = Exception("UnauthorizedAccessException: " + str(error)) + exc.quiet = True + raise exc elif status not in ("401", "Auth"): # Tell userclient token has been revoked. @@ -323,7 +333,9 @@ class DownloadUtils(object): xbmcgui.Dialog().notification(heading="Error connecting", message="Unauthorized.", icon=xbmcgui.NOTIFICATION_ERROR) - raise internal_exceptions.ExceptionWrapper("401: " + str(error)) + exc = Exception("401: " + str(error)) + exc.quiet = True + raise exc except requests.exceptions.RequestException as error: log.error("unknown error connecting to: %s", url) diff --git a/resources/lib/ga_client.py b/resources/lib/ga_client.py index b0a6a8c4..843ad054 100644 --- a/resources/lib/ga_client.py +++ b/resources/lib/ga_client.py @@ -8,7 +8,6 @@ import hashlib import xbmc import time from utils import window, settings, language as lang -import internal_exceptions log = logging.getLogger("EMBY."+__name__) @@ -23,15 +22,11 @@ def log_error(errors=(Exception, )): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except internal_exceptions.ExceptionWrapper as error: - log.exception(error) - log.error("log_error: %s \n args: %s \n kwargs: %s", - func.__name__, args, kwargs) - raise except errors as error: - ga = GoogleAnalytics() - errStrings = ga.formatException() - ga.sendEventData("Exception", errStrings[0], errStrings[1], True) + if not (hasattr(error, 'quiet') and error.quiet): + ga = GoogleAnalytics() + errStrings = ga.formatException() + ga.sendEventData("Exception", errStrings[0], errStrings[1], True) log.exception(error) log.error("log_error: %s \n args: %s \n kwargs: %s", func.__name__, args, kwargs) diff --git a/resources/lib/internal_exceptions.py b/resources/lib/internal_exceptions.py deleted file mode 100644 index 9401b1dd..00000000 --- a/resources/lib/internal_exceptions.py +++ /dev/null @@ -1,5 +0,0 @@ - -# this is an internal exception wrapper that is used to raise exceptions -# when you dont want them logged ot the metric logging system -class ExceptionWrapper(Exception): - pass diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index f1cf56c6..22b975c9 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -24,7 +24,6 @@ import views from objects import Movies, MusicVideos, TVShows, Music from utils import window, settings, language as lang, should_stop from ga_client import GoogleAnalytics -import internal_exceptions ################################################################################################## @@ -619,7 +618,7 @@ class LibrarySync(threading.Thread): except Exception as e: ga = GoogleAnalytics() errStrings = ga.formatException() - if type(e) != internal_exceptions.ExceptionWrapper: + if not (hasattr(e, 'quiet') and e.quiet): ga.sendEventData("Exception", errStrings[0], errStrings[1]) window('emby_dbScan', clear=True) log.exception(e) diff --git a/resources/lib/objects/_common.py b/resources/lib/objects/_common.py index c68b9b8b..92db11f6 100644 --- a/resources/lib/objects/_common.py +++ b/resources/lib/objects/_common.py @@ -15,7 +15,6 @@ import downloadutils import read_embyserver as embyserver from ga_client import GoogleAnalytics from utils import window, settings, dialog, language as lang, should_stop -import internal_exceptions ################################################################################################## @@ -30,14 +29,12 @@ def catch_except(errors=(Exception, ), default_value=False): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) - except internal_exceptions.ExceptionWrapper as error: - log.exception(error) - raise except sqlite3.Error as error: raise except errors as error: - errStrings = ga.formatException() - ga.sendEventData("Exception", errStrings[0], errStrings[1], True) + if not (hasattr(error, 'quiet') and error.quiet): + errStrings = ga.formatException() + ga.sendEventData("Exception", errStrings[0], errStrings[1], True) log.exception(error) log.error("function: %s \n args: %s \n kwargs: %s", func.__name__, args, kwargs) diff --git a/resources/lib/service_entry.py b/resources/lib/service_entry.py index 98ee700b..b9e54333 100644 --- a/resources/lib/service_entry.py +++ b/resources/lib/service_entry.py @@ -22,7 +22,6 @@ from views import VideoNodes from utils import window, settings, dialog, language as lang from ga_client import GoogleAnalytics import hashlib -import internal_exceptions ################################################################################################# @@ -107,7 +106,9 @@ class Service(object): # Profile change happened, terminate this thread and others log.info("Kodi profile was: %s and changed to: %s. Terminating old Emby thread.", kodi_profile, window('emby_kodiProfile')) - raise internal_exceptions.ExceptionWrapper("Kodi profile changed detected") + exc = Exception("Kodi profile changed detected") + exc.quiet = True + raise exc # Before proceeding, need to make sure: # 1. Server is online diff --git a/service.py b/service.py index 868c5147..17c303c4 100644 --- a/service.py +++ b/service.py @@ -22,7 +22,6 @@ import loghandler from service_entry import Service from utils import settings from ga_client import GoogleAnalytics -import internal_exceptions ################################################################################################# @@ -42,14 +41,11 @@ if __name__ == "__main__": raise RuntimeError("Abort event while waiting to start Emby for kodi") # Start the service service.service_entry_point() - except internal_exceptions.ExceptionWrapper as error: - log.exception(error) - log.info("Forcing shutdown") - service.shutdown() except Exception as error: - ga = GoogleAnalytics() - errStrings = ga.formatException() - ga.sendEventData("Exception", errStrings[0], errStrings[1]) + if not (hasattr(error, 'quiet') and error.quiet): + ga = GoogleAnalytics() + errStrings = ga.formatException() + ga.sendEventData("Exception", errStrings[0], errStrings[1]) log.exception(error) log.info("Forcing shutdown") service.shutdown()