From f7f4e41c95b97cbd39a4d2ba975ca69d9f39ecc7 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Mon, 11 Apr 2022 17:16:07 -0700 Subject: [PATCH] Catch exception when displaying raw tags --- comictaggerlib/logwindow.py | 8 ++++++-- comictaggerlib/ui/qtutils.py | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/comictaggerlib/logwindow.py b/comictaggerlib/logwindow.py index eb24397..7270f50 100644 --- a/comictaggerlib/logwindow.py +++ b/comictaggerlib/logwindow.py @@ -20,6 +20,7 @@ import logging from PyQt5 import QtCore, QtWidgets, uic from comictaggerlib.settings import ComicTaggerSettings +from comictaggerlib.ui import qtutils logger = logging.getLogger(__name__) @@ -41,6 +42,9 @@ class LogWindow(QtWidgets.QDialog): def set_text(self, text): try: text = text.decode() - except: + self.textEdit.setPlainText(text) + except AttributeError: pass - self.textEdit.setPlainText(text) + except Exception as e: + logger.exception("Displaying raw tags failed") + qtutils.qt_error("Displaying raw tags failed:", e) diff --git a/comictaggerlib/ui/qtutils.py b/comictaggerlib/ui/qtutils.py index e9d82c1..f2fb136 100644 --- a/comictaggerlib/ui/qtutils.py +++ b/comictaggerlib/ui/qtutils.py @@ -2,13 +2,14 @@ import io import logging +import traceback from comictaggerlib.settings import ComicTaggerSettings logger = logging.getLogger(__name__) try: - from PyQt5 import QtGui + from PyQt5 import QtGui, QtWidgets qt_available = True except ImportError: @@ -74,3 +75,10 @@ if qt_available: if not success: img.load(ComicTaggerSettings.get_graphic("nocover.png")) return img + + def qt_error(msg: str, e: Exception = None): + trace = "" + if e: + trace = "\n".join(traceback.format_exception(type(e), e, e.__traceback__)) + + QtWidgets.QMessageBox.critical(QtWidgets.QMainWindow(), "Error", msg + trace)