diff --git a/BackgroundTask.py b/BackgroundTask.py index 376796f..234b000 100644 --- a/BackgroundTask.py +++ b/BackgroundTask.py @@ -209,7 +209,7 @@ def execute(self): self.rseData.frame.event_generate(RseData.EVENT_RSE_UPDATE_AVAILABLE, when="tail") break except Exception as e: - print("{plugin_name}: Failed to retrieve information about available updates. Error: {e}".format(plugin_name=RseData.PLUGIN_NAME, e=e)) + RseData.printError("Failed to retrieve information about available updates. Error: {e}".format(e=e)) class TimedTask(BackgroundTask): diff --git a/Backgroundworker.py b/Backgroundworker.py index ad054e5..1f7b958 100644 --- a/Backgroundworker.py +++ b/Backgroundworker.py @@ -19,6 +19,9 @@ from threading import Thread, Timer from BackgroundTask import TimedTask +import traceback + +from RseData import RseData class BackgroundWorker(Thread): @@ -46,7 +49,11 @@ def run(self): if not task: break else: - task.execute() + try: + task.execute() + except Exception as e: + RseData.printError("Exception occurred in background task {bg}: {e}".format(bg=task.__class__.__name__, e=e)) + traceback.print_exc() self.queue.task_done() diff --git a/RseData.py b/RseData.py index 370e87a..9dd56c6 100644 --- a/RseData.py +++ b/RseData.py @@ -17,7 +17,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ import plug -import sys import os import time import math @@ -194,8 +193,7 @@ def openLocalDatabase(self): self.localDbCursor = self.localDbConnection.cursor() except Exception as e: error_msg = "{plugin_name}: Local cache database could not be opened".format(plugin_name=RseData.PLUGIN_NAME) - print(error_msg) - plug.show_error(error_msg) + RseData.printError(error_msg, showError=True) def closeLocalDatabase(self): if not self.isLocalDatabaseAccessible(): @@ -384,7 +382,6 @@ def initialize(self): self.closeLocalDatabase() # initialize dictionaries - # self.openRemoteDatabase() if len(self.projectsDict) == 0: url = urlopen("https://cyberlord.de/rse/projects.py", timeout=10) response = url.read() @@ -394,4 +391,17 @@ def initialize(self): def printDebug(self, msg): if self.debug: - print("{plugin_name} (Debug): {msg}".format(plugin_name=RseData.PLUGIN_NAME, msg=msg)) + print("{plugin_name}-{version} (Debug): {msg}".format(plugin_name=RseData.PLUGIN_NAME, version=RseData.VERSION, msg=msg)) + + @staticmethod + def printError(msg, showError=False): + """ + Prints/logs an error and can show it on the main window if necessary. + :param msg: The error message + :param showError: Whether to show it on the EDMC main window or not + :return: + """ + errorMessage = "{plugin_name}-{version}: {msg}".format(plugin_name=RseData.PLUGIN_NAME, version=RseData.VERSION, msg=msg) + print(errorMessage) + if showError: + plug.show_error(errorMessage)