Another error message for broken profile

This commit is contained in:
Dpeta 2022-03-18 03:09:48 +00:00
parent 862af2c849
commit 72f6b32668
2 changed files with 34 additions and 11 deletions

View file

@ -2997,8 +2997,25 @@ class PesterWindow(MovingWindow):
if handle == self.profile().handle: if handle == self.profile().handle:
self.chooseprofile = None self.chooseprofile = None
return return
self.userprofile = userProfile(handle) try:
self.changeTheme(self.userprofile.getTheme()) self.userprofile = userProfile(handle)
self.changeTheme(self.userprofile.getTheme())
except (json.JSONDecodeError, FileNotFoundError) as e:
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setWindowTitle(":(")
msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links
self.filename = _datadir+"pesterchum.js"
msgBox.setText("<html><h3>Failed to load: " + ("<a href='%s'>%s/%s.js</a>" % (self.profiledir, self.profiledir, user)) + \
"<br><br> Try to check for syntax errors if the file exists." + \
"<br><br>If you got this message at launch you may want to change your default profile." + \
"<br><br>" + str(e) + "<\h3><\html>")
#"\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \
#_datadir+"pesterchum.js" + \
#"\"")
PchumLog.critical(e)
msgBox.exec_()
return
else: else:
handle = str(self.chooseprofile.chumHandle.text()) handle = str(self.chooseprofile.chumHandle.text())
if handle == self.profile().handle: if handle == self.profile().handle:

View file

@ -64,12 +64,17 @@ class PesterLog(object):
os.makedirs("%s/%s/%s/%s" % (self.logpath, self.handle, handle, format)) os.makedirs("%s/%s/%s/%s" % (self.logpath, self.handle, handle, format))
try: try:
fp = codecs.open("%s/%s/%s/%s/%s.%s.txt" % (self.logpath, self.handle, handle, format, handle, time), encoding='utf-8', mode='a') fp = codecs.open("%s/%s/%s/%s/%s.%s.txt" % (self.logpath, self.handle, handle, format, handle, time), encoding='utf-8', mode='a')
except IOError: except (IOError, OSError) as e:
errmsg = QtWidgets.QMessageBox(self) # Catching this exception does not stop pchum from dying if we run out of file handles </3
PchumLog.critical(e)
errmsg = QtWidgets.QMessageBox()
errmsg.setIcon(QtWidgets.QMessageBox.Warning)
errmsg.setText("Warning: Pesterchum could not open the log file for %s!" % (handle)) errmsg.setText("Warning: Pesterchum could not open the log file for %s!" % (handle))
errmsg.setInformativeText("Your log for %s will not be saved because something went wrong. We suggest restarting Pesterchum. Sorry :(" % (handle)) errmsg.setInformativeText("Your log for %s will not be saved because something went wrong. We suggest restarting Pesterchum. Sorry :(" % (handle))
errmsg.show() errmsg.setWindowTitle(":(")
continue errmsg.exec_()
PchumLog.debug("post-error msg")
self.convos[handle][format] = fp self.convos[handle][format] = fp
for (format, t) in modes.items(): for (format, t) in modes.items():
f = self.convos[handle][format] f = self.convos[handle][format]
@ -113,6 +118,7 @@ class userConfig(object):
PchumLog.critical("failed to load pesterchum.js") PchumLog.critical("failed to load pesterchum.js")
PchumLog.critical(e) PchumLog.critical(e)
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
msgbox.setIcon(QtWidgets.QMessageBox.Warning)
msgbox.setWindowTitle(":(") msgbox.setWindowTitle(":(")
msgbox.setTextFormat(QtCore.Qt.RichText) # Clickable html links msgbox.setTextFormat(QtCore.Qt.RichText) # Clickable html links
msgbox.setInformativeText("<html><h3>Failed to load pesterchum.js, this might require manual intervention.<br><br>\ msgbox.setInformativeText("<html><h3>Failed to load pesterchum.js, this might require manual intervention.<br><br>\
@ -461,7 +467,7 @@ with a backup from: <a href='%s'>%s</a></h3></html>" % (_datadir, self.filename,
PchumLog.warning(x + " removed from profile list.") PchumLog.warning(x + " removed from profile list.")
msgBox = QtWidgets.QMessageBox() msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Information) msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setWindowTitle(":(") msgBox.setWindowTitle(":(")
msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links
self.filename = _datadir+"pesterchum.js" self.filename = _datadir+"pesterchum.js"
@ -508,14 +514,14 @@ class userProfile(object):
try: try:
with open("%s/%s.js" % (self.profiledir, user)) as fp: with open("%s/%s.js" % (self.profiledir, user)) as fp:
self.userprofile = json.load(fp) self.userprofile = json.load(fp)
except json.JSONDecodeError as e: except (json.JSONDecodeError, FileNotFoundError) as e:
msgBox = QtWidgets.QMessageBox() msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Information) msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setWindowTitle(":(") msgBox.setWindowTitle(":(")
msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links
self.filename = _datadir+"pesterchum.js" self.filename = _datadir+"pesterchum.js"
msgBox.setText("<html><h3>Failed to open: " + ("<a href='%s'>%s/%s.js</a>" % (self.profiledir, self.profiledir, user)) + \ msgBox.setText("<html><h3>Failed to load: " + ("<a href='%s'>%s/%s.js</a>" % (self.profiledir, self.profiledir, user)) + \
"<br><br> Try to check for syntax errors." + \ "<br><br> Try to check for syntax errors if the file exists." + \
"<br><br>If you got this message at launch you may want to change your default profile." + \ "<br><br>If you got this message at launch you may want to change your default profile." + \
"<br><br>" + str(e) + "<\h3><\html>") "<br><br>" + str(e) + "<\h3><\html>")
#"\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \ #"\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \