Only try to show ApplicationError dialog when we have a QApplication

This commit is contained in:
Keith Edmunds 2025-03-08 11:42:59 +00:00
parent 1f10692c15
commit 76039aa5e6

View File

@ -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'))