From 0aea7bdb5c67e7dde3be31cfd1a8d48b72c5d322 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jun 2016 14:54:21 +0200 Subject: [PATCH 1/3] Use callLater to set the active machine in MachineManager This prevents exceptions in setActiveMachine from preventing Cura to start. --- cura/MachineManagerModel.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 0e7230fb79..86b044ae84 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -38,8 +38,7 @@ class MachineManagerModel(QObject): if active_machine_id != "": # An active machine was saved, so restore it. - self.setActiveMachine(active_machine_id) - pass + Application.getInstance().callLater(self.setActiveMachine, active_machine_id) globalContainerChanged = pyqtSignal() activeMaterialChanged = pyqtSignal() From 44f8744c847c5a8a466c75247c61c969742299bc Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jun 2016 14:56:08 +0200 Subject: [PATCH 2/3] Use the Logger to report uncaught exceptions Makes for a nicer and clearer output of uncaught exceptions --- cura/CrashHandler.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cura/CrashHandler.py b/cura/CrashHandler.py index 57de2959eb..4efcfbe1e5 100644 --- a/cura/CrashHandler.py +++ b/cura/CrashHandler.py @@ -5,6 +5,8 @@ import webbrowser from PyQt5.QtCore import QT_VERSION_STR, PYQT_VERSION_STR, QCoreApplication from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QTextEdit + +from UM.Logger import Logger from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") @@ -13,7 +15,10 @@ def show(exception_type, value, tb): if QCoreApplication.instance(): debug_mode = QCoreApplication.instance().getCommandLineOption("debug-mode", False) - traceback.print_exception(exception_type, value, tb) + Logger.log("c", "An uncaught exception has occurred!") + for line in traceback.format_exception(exception_type, value, tb): + for part in line.rstrip("\n").split("\n"): + Logger.log("c", part) if not debug_mode: return From a4e37d9ae7e2fc04dcee1558018cbc2aaa88a393 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 10 Jun 2016 15:07:59 +0200 Subject: [PATCH 3/3] Mark certain types of exceptions as fatal and abort the application if they occur We simply cannot recover properly from things like an uncaught MemoryError since that usually means any follow up operation will also fail. So Instead of silently ignoring it and having the application in a broken state we properly abort. Right now the list of fatal exceptions is a bare minimum that contains the most prominent things we cannot recover from. --- cura/CrashHandler.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cura/CrashHandler.py b/cura/CrashHandler.py index 4efcfbe1e5..e86e407902 100644 --- a/cura/CrashHandler.py +++ b/cura/CrashHandler.py @@ -10,6 +10,17 @@ from UM.Logger import Logger from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") +# List of exceptions that should be considered "fatal" and abort the program. +# These are primarily some exception types that we simply cannot really recover from +# (MemoryError and SystemError) and exceptions that indicate grave errors in the +# code that cause the Python interpreter to fail (SyntaxError, ImportError). +fatal_exception_types = [ + MemoryError, + SyntaxError, + ImportError, + SystemError, +] + def show(exception_type, value, tb): debug_mode = False if QCoreApplication.instance(): @@ -20,7 +31,7 @@ def show(exception_type, value, tb): for part in line.rstrip("\n").split("\n"): Logger.log("c", part) - if not debug_mode: + if not debug_mode and exception_type not in fatal_exception_types: return application = QCoreApplication.instance() @@ -34,7 +45,7 @@ def show(exception_type, value, tb): label = QLabel(dialog) layout.addWidget(label) - label.setText(catalog.i18nc("@label", "

An uncaught exception has occurred!

Please use the information below to post a bug report at http://github.com/Ultimaker/Cura/issues

")) + label.setText(catalog.i18nc("@label", "

A fatal exception has occurred that we could not recover from!

Please use the information below to post a bug report at http://github.com/Ultimaker/Cura/issues

")) textarea = QTextEdit(dialog) layout.addWidget(textarea)