Only try to show ApplicationError dialog when we have a QApplication
This commit is contained in:
parent
1f10692c15
commit
76039aa5e6
@ -10,7 +10,7 @@ import traceback
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
# PyQt imports
|
# PyQt imports
|
||||||
from PyQt6.QtWidgets import QMessageBox
|
from PyQt6.QtWidgets import QApplication, QMessageBox
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
import stackprinter # type: ignore
|
import stackprinter # type: ignore
|
||||||
@ -79,14 +79,14 @@ log = logging.getLogger(Config.LOG_NAME)
|
|||||||
|
|
||||||
|
|
||||||
def handle_exception(exc_type, exc_value, exc_traceback):
|
def handle_exception(exc_type, exc_value, exc_traceback):
|
||||||
if issubclass(exc_type, ApplicationError):
|
|
||||||
error = str(exc_value)
|
error = str(exc_value)
|
||||||
log.error(error)
|
if QApplication.instance() is not None:
|
||||||
QMessageBox.critical(None, "Application Error", error)
|
QMessageBox.critical(None, "Application Error", error)
|
||||||
|
if issubclass(exc_type, ApplicationError):
|
||||||
|
log.error(error)
|
||||||
else:
|
else:
|
||||||
# Handle unexpected errors (log and display)
|
# Handle unexpected errors (log and display)
|
||||||
error_msg = "".join(traceback.format_exception(exc_type, exc_value, exc_traceback))
|
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'))
|
print(stackprinter.format(exc_value, suppressed_paths=['/.venv'], style='darkbg'))
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user