Improve error reporting when a world fails to open

This commit is contained in:
David Vierra 2016-03-27 04:28:54 -10:00
parent 9127dcd786
commit 84c7c24a87
3 changed files with 15 additions and 7 deletions

View File

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

View File

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

View File

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