diff --git a/addon.xml b/addon.xml index 71fcf025..ddab9325 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/ga_client.py b/resources/lib/ga_client.py index 8a886fc9..ce7394a6 100644 --- a/resources/lib/ga_client.py +++ b/resources/lib/ga_client.py @@ -9,7 +9,7 @@ import xbmc import platform import xbmcgui import time -from utils import window, settings, language as lang +from utils import settings, language as lang log = logging.getLogger("EMBY."+__name__) @@ -18,6 +18,24 @@ log = logging.getLogger("EMBY."+__name__) logEventHistory = {} +# wrap a function to catch, log and then re throw an exception +def log_error(errors=(Exception, )): + def decorator(func): + def wrapper(*args, **kwargs): + try: + return func(*args, **kwargs) + except errors as error: + 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) + raise + return wrapper + return decorator + +# main GA class class GoogleAnalytics(): testing = False diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 6247a82e..a66e790b 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -12,6 +12,7 @@ import downloadutils import embydb_functions as embydb import playbackutils as pbutils from utils import window, settings, kodiSQL +from ga_client import log_error ################################################################################################# @@ -56,6 +57,7 @@ class KodiMonitor(xbmc.Monitor): log.info("New context setting: %s", current_context) window('emby_context', value=current_context) + @log_error() def onNotification(self, sender, method, data): if method not in ('Playlist.OnAdd', 'Player.OnStop', 'Player.OnClear'): diff --git a/resources/lib/player.py b/resources/lib/player.py index 3f19979a..9505238d 100644 --- a/resources/lib/player.py +++ b/resources/lib/player.py @@ -14,7 +14,7 @@ import downloadutils import kodidb_functions as kodidb import websocket_client as wsc from utils import window, settings, language as lang -from ga_client import GoogleAnalytics +from ga_client import GoogleAnalytics, log_error ################################################################################################# @@ -44,6 +44,7 @@ class Player(xbmc.Player): log.debug("Starting playback monitor.") xbmc.Player.__init__(self) + @log_error() def onPlayBackStarted(self): # Will be called when xbmc starts playing a file self.stopAll() @@ -356,6 +357,7 @@ class Player(xbmc.Player): log.debug("Report: %s" % postdata) self.ws.send_progress_update(postdata) + @log_error() def onPlayBackPaused(self): currentFile = self.currentFile @@ -366,6 +368,7 @@ class Player(xbmc.Player): self.reportPlayback() + @log_error() def onPlayBackResumed(self): currentFile = self.currentFile @@ -376,6 +379,7 @@ class Player(xbmc.Player): self.reportPlayback() + @log_error() def onPlayBackSeek(self, time, seekOffset): # Make position when seeking a bit more accurate currentFile = self.currentFile @@ -387,6 +391,7 @@ class Player(xbmc.Player): self.reportPlayback() + @log_error() def onPlayBackStopped(self): # Will be called when user stops xbmc playing a file log.debug("ONPLAYBACK_STOPPED") @@ -396,6 +401,7 @@ class Player(xbmc.Player): log.info("Clear playlist properties.") self.stopAll() + @log_error() def onPlayBackEnded(self): # Will be called when xbmc stops playing a file log.debug("ONPLAYBACK_ENDED") diff --git a/resources/lib/websocket_client.py b/resources/lib/websocket_client.py index fb86f82a..52d8ace2 100644 --- a/resources/lib/websocket_client.py +++ b/resources/lib/websocket_client.py @@ -15,6 +15,7 @@ import librarysync import playlist import userclient from utils import window, settings, dialog, language as lang, JSONRPC +from ga_client import log_error ################################################################################################## @@ -60,6 +61,7 @@ class WebSocketClient(threading.Thread): except Exception as error: log.exception(error) + @log_error() def on_message(self, ws, message): result = json.loads(message)