diff --git a/app/log.py b/app/log.py index 2adec79..c729025 100644 --- a/app/log.py +++ b/app/log.py @@ -10,7 +10,7 @@ import traceback import yaml # PyQt imports -from PyQt6.QtWidgets import QMessageBox +from PyQt6.QtWidgets import QApplication, QMessageBox # Third party imports import stackprinter # type: ignore @@ -79,14 +79,14 @@ log = logging.getLogger(Config.LOG_NAME) def handle_exception(exc_type, exc_value, exc_traceback): - if issubclass(exc_type, ApplicationError): - error = str(exc_value) - log.error(error) + error = str(exc_value) + if QApplication.instance() is not None: QMessageBox.critical(None, "Application Error", error) + if issubclass(exc_type, ApplicationError): + log.error(error) else: # Handle unexpected errors (log and display) error_msg = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback)) - QMessageBox.critical(None, "Application Error", error_msg) print(stackprinter.format(exc_value, suppressed_paths=['/.venv'], style='darkbg'))