Fixed issue where Pesterchum crashed if a quirk was malformed

This commit is contained in:
Dpeta 2021-03-25 18:41:07 +01:00
parent 684846a804
commit a3c1c90ec0
3 changed files with 26 additions and 12 deletions

View file

@ -1,4 +1,4 @@
import os, sys, re, ostools import os, sys, re, ostools, logging
try: try:
import lua import lua
except ImportError: except ImportError:
@ -51,11 +51,18 @@ class LuaQuirks(ScriptQuirks):
if not isinstance(CommandWrapper("test"), str): if not isinstance(CommandWrapper("test"), str):
raise Exception raise Exception
except: except:
print("Quirk malformed: %s" % (name)) #print("Quirk malformed: %s" % (name))
msgbox = QtWidgets.QMessageBox() logging.error("Quirk malformed: %s" % (name))
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (name)) # Since this is executed before QApplication is constructed,
msgbox.exec_() # This prevented pesterchum from starting entirely when a quirk was malformed :/
# (QWidget: Must construct a QApplication before a QWidget)
if QtWidgets.QApplication.instance() != None:
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (name))
msgbox.exec_()
else: else:
self.quirks[name] = CommandWrapper self.quirks[name] = CommandWrapper

View file

@ -1,6 +1,7 @@
import os, sys, imp, re, ostools import os, sys, imp, re, ostools
from quirks import ScriptQuirks from quirks import ScriptQuirks
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
import logging
class PythonQuirks(ScriptQuirks): class PythonQuirks(ScriptQuirks):
def loadModule(self, name, filename): def loadModule(self, name, filename):
@ -25,11 +26,18 @@ class PythonQuirks(ScriptQuirks):
if not isinstance(obj("test"), str): if not isinstance(obj("test"), str):
raise Exception raise Exception
except: except:
print("Quirk malformed: %s" % (obj.command)) #print("Quirk malformed: %s" % (obj.command))
msgbox = QtWidgets.QMessageBox() logging.error("Quirk malformed: %s" % (obj.command))
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (obj.command)) # Since this is executed before QApplication is constructed,
msgbox.exec_() # This prevented pesterchum from starting entirely when a quirk was malformed :/
# (QWidget: Must construct a QApplication before a QWidget)
if QtWidgets.QApplication.instance() != None:
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (obj.command))
msgbox.exec_()
else: else:
self.quirks[obj.command] = obj self.quirks[obj.command] = obj

View file

@ -60,7 +60,6 @@ class RandomHandler(QtCore.QObject):
if l[1] == "x": if l[1] == "x":
from PyQt5 import QtGui, QtWidgets from PyQt5 import QtGui, QtWidgets
msgbox = QtWidgets.QMessageBox() msgbox = QtWidgets.QMessageBox()
msgbox.setStyleSheet("QMessageBox{" + self.theme["main/defaultwindow/style"] + "}")
msgbox.setText("Unable to fetch you a random encounter!") msgbox.setText("Unable to fetch you a random encounter!")
msgbox.setInformativeText("Try again later :(") msgbox.setInformativeText("Try again later :(")
msgbox.exec_() msgbox.exec_()