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:
import lua
except ImportError:
@ -51,11 +51,18 @@ class LuaQuirks(ScriptQuirks):
if not isinstance(CommandWrapper("test"), str):
raise Exception
except:
print("Quirk malformed: %s" % (name))
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (name))
msgbox.exec_()
#print("Quirk malformed: %s" % (name))
logging.error("Quirk malformed: %s" % (name))
# Since this is executed before QApplication is constructed,
# 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:
self.quirks[name] = CommandWrapper

View file

@ -1,6 +1,7 @@
import os, sys, imp, re, ostools
from quirks import ScriptQuirks
from PyQt5 import QtCore, QtGui, QtWidgets
import logging
class PythonQuirks(ScriptQuirks):
def loadModule(self, name, filename):
@ -25,11 +26,18 @@ class PythonQuirks(ScriptQuirks):
if not isinstance(obj("test"), str):
raise Exception
except:
print("Quirk malformed: %s" % (obj.command))
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (obj.command))
msgbox.exec_()
#print("Quirk malformed: %s" % (obj.command))
logging.error("Quirk malformed: %s" % (obj.command))
# Since this is executed before QApplication is constructed,
# 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:
self.quirks[obj.command] = obj

View file

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