mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-21 05:37:50 -06:00
Handle all uncaught exceptions through CrashHandler and gracefully fail if we have no QCoreApplication
This commit is contained in:
parent
cb06668628
commit
803b4fde8d
2 changed files with 18 additions and 9 deletions
|
@ -3,10 +3,15 @@ import platform
|
||||||
import traceback
|
import traceback
|
||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR
|
from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QCoreApplication
|
||||||
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit
|
from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit
|
||||||
|
|
||||||
def show():
|
def show(type, value, tb):
|
||||||
|
application = QCoreApplication.instance()
|
||||||
|
if not application:
|
||||||
|
traceback.print_exception(type, value, tb)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
dialog = QDialog()
|
dialog = QDialog()
|
||||||
dialog.setWindowTitle("Oops!")
|
dialog.setWindowTitle("Oops!")
|
||||||
|
|
||||||
|
@ -25,7 +30,7 @@ def show():
|
||||||
except:
|
except:
|
||||||
version = "Unknown"
|
version = "Unknown"
|
||||||
|
|
||||||
trace = "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
|
trace = "".join(traceback.format_exception(type, value, tb))
|
||||||
|
|
||||||
crash_info = "Version: {0}\nPlatform: {1}\nQt: {2}\nPyQt: {3}\n\nException:\n{4}"
|
crash_info = "Version: {0}\nPlatform: {1}\nQt: {2}\nPyQt: {3}\n\nException:\n{4}"
|
||||||
crash_info = crash_info.format(version, platform.platform(), QT_VERSION_STR, PYQT_VERSION_STR, trace)
|
crash_info = crash_info.format(version, platform.platform(), QT_VERSION_STR, PYQT_VERSION_STR, trace)
|
||||||
|
@ -39,3 +44,4 @@ def show():
|
||||||
buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues"))
|
buttons.helpRequested.connect(lambda: webbrowser.open("http://github.com/Ultimaker/Cura/issues"))
|
||||||
|
|
||||||
dialog.exec_()
|
dialog.exec_()
|
||||||
|
exit(1)
|
||||||
|
|
15
cura_app.py
15
cura_app.py
|
@ -3,12 +3,15 @@
|
||||||
# Copyright (c) 2015 Ultimaker B.V.
|
# Copyright (c) 2015 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the AGPLv3 or higher.
|
# Cura is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
try:
|
import sys
|
||||||
import cura.CuraApplication
|
|
||||||
|
|
||||||
app = cura.CuraApplication.CuraApplication.getInstance()
|
def exceptHook(type, value, traceback):
|
||||||
app.run()
|
|
||||||
except Exception as e:
|
|
||||||
import cura.CrashHandler
|
import cura.CrashHandler
|
||||||
cura.CrashHandler.show()
|
cura.CrashHandler.show(type, value, traceback)
|
||||||
|
|
||||||
|
sys.excepthook = exceptHook
|
||||||
|
|
||||||
|
import cura.CuraApplication
|
||||||
|
|
||||||
|
app = cura.CuraApplication.CuraApplication.getInstance()
|
||||||
|
app.run()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue