From 84c7c24a87cb1e33902f232505d77cf8315a7e9b Mon Sep 17 00:00:00 2001 From: David Vierra Date: Sun, 27 Mar 2016 04:28:54 -1000 Subject: [PATCH] Improve error reporting when a world fails to open --- src/mcedit2/editorapp.py | 2 +- src/mcedit2/widgets/layout.py | 14 +++++++++++--- src/mcedit2/worldlist.py | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/mcedit2/editorapp.py b/src/mcedit2/editorapp.py index 37e7308..8e5736e 100644 --- a/src/mcedit2/editorapp.py +++ b/src/mcedit2/editorapp.py @@ -709,7 +709,7 @@ class MCEditApp(QtGui.QApplication): except Exception as e: log.exception("EditorSession failed to open %s: %r", filename, e) errorTab = QtGui.QWidget() - setWidgetError(errorTab, e) + setWidgetError(errorTab, e, "An error occurred while opening %s" % filename) self.tabWidget.addTab(errorTab, "Failed to open %s" % filename) fileLoadingDialog.reset() diff --git a/src/mcedit2/widgets/layout.py b/src/mcedit2/widgets/layout.py index bac89fc..a4b92ec 100644 --- a/src/mcedit2/widgets/layout.py +++ b/src/mcedit2/widgets/layout.py @@ -1,4 +1,7 @@ from __future__ import absolute_import, division, print_function, unicode_literals + +import traceback + from PySide import QtGui from PySide.QtCore import Qt @@ -45,7 +48,7 @@ def Column(*a, **kw): box.setContentsMargins(margin, margin, margin, margin) return box -def setWidgetError(widget, exc): +def setWidgetError(widget, exc, msg = "An error has occurred."): """ Add a subwidget to `widget` that displays the error message for the exception `exc` :param widget: @@ -53,6 +56,11 @@ def setWidgetError(widget, exc): :return: """ layout = QtGui.QVBoxLayout() - layout.addWidget(QtGui.QLabel(exc.message)) - layout.addStretch() + textArea = QtGui.QTextEdit() + textArea.setReadOnly(True) + message = msg + "\n" + message += str(exc) + "\n\n" + message += traceback.format_exc() + textArea.setText(message) + layout.addWidget(textArea) widget.setLayout(layout) diff --git a/src/mcedit2/worldlist.py b/src/mcedit2/worldlist.py index 699ba1b..b309e4c 100644 --- a/src/mcedit2/worldlist.py +++ b/src/mcedit2/worldlist.py @@ -353,8 +353,8 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList): self.worldListModel = WorldListModel(worldFiles) self.worldListView.setModel(self.worldListModel) - except EnvironmentError as e: - setWidgetError(self, e) + except Exception as e: + setWidgetError(self, e, "An error occurred while scanning the saves folder.") def openWorldClicked(self): QtGui.qApp.chooseOpenWorld() @@ -382,7 +382,7 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList): except (EnvironmentError, LevelFormatError, zipfile.BadZipfile) as e: self.errorWidget = QtGui.QWidget() - setWidgetError(self.errorWidget, e) + setWidgetError(self.errorWidget, e, "An error occurred while reading the world %s." % filename) self.stackedWidget.addWidget(self.errorWidget) self.stackedWidget.setCurrentWidget(self.errorWidget)