diff --git a/pesterchum.py b/pesterchum.py index 13c6ba5..9d7f884 100755 --- a/pesterchum.py +++ b/pesterchum.py @@ -2997,8 +2997,25 @@ class PesterWindow(MovingWindow): if handle == self.profile().handle: self.chooseprofile = None return - self.userprofile = userProfile(handle) - self.changeTheme(self.userprofile.getTheme()) + try: + 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("

Failed to load: " + ("%s/%s.js" % (self.profiledir, self.profiledir, user)) + \ + "

Try to check for syntax errors if the file exists." + \ + "

If you got this message at launch you may want to change your default profile." + \ + "

" + 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: handle = str(self.chooseprofile.chumHandle.text()) if handle == self.profile().handle: diff --git a/profile.py b/profile.py index 496b529..231d62a 100644 --- a/profile.py +++ b/profile.py @@ -64,12 +64,17 @@ class PesterLog(object): os.makedirs("%s/%s/%s/%s" % (self.logpath, self.handle, handle, format)) try: 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: - errmsg = QtWidgets.QMessageBox(self) + except (IOError, OSError) as e: + # Catching this exception does not stop pchum from dying if we run out of file handles

Failed to load pesterchum.js, this might require manual intervention.

\ @@ -461,7 +467,7 @@ with a backup from: %s

" % (_datadir, self.filename, PchumLog.warning(x + " removed from profile list.") msgBox = QtWidgets.QMessageBox() - msgBox.setIcon(QtWidgets.QMessageBox.Information) + msgBox.setIcon(QtWidgets.QMessageBox.Warning) msgBox.setWindowTitle(":(") msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links self.filename = _datadir+"pesterchum.js" @@ -508,14 +514,14 @@ class userProfile(object): try: with open("%s/%s.js" % (self.profiledir, user)) as fp: self.userprofile = json.load(fp) - except json.JSONDecodeError as e: + except (json.JSONDecodeError, FileNotFoundError) as e: msgBox = QtWidgets.QMessageBox() - msgBox.setIcon(QtWidgets.QMessageBox.Information) + msgBox.setIcon(QtWidgets.QMessageBox.Warning) msgBox.setWindowTitle(":(") msgBox.setTextFormat(QtCore.Qt.RichText) # Clickable html links self.filename = _datadir+"pesterchum.js" - msgBox.setText("

Failed to open: " + ("%s/%s.js" % (self.profiledir, self.profiledir, user)) + \ - "

Try to check for syntax errors." + \ + msgBox.setText("

Failed to load: " + ("%s/%s.js" % (self.profiledir, self.profiledir, user)) + \ + "

Try to check for syntax errors if the file exists." + \ "

If you got this message at launch you may want to change your default profile." + \ "

" + str(e) + "<\h3><\html>") #"\" if pesterchum acts oddly you might want to try backing up and then deleting \"" + \