mirror of
https://github.com/SELinuxProject/setools
synced 2025-04-04 23:39:29 +00:00
apol: Improve tab loading error handling.
Add explicit type conversions so the Qt C++ code always gets the expected type. Add additional handlers to catch the exceptions and provide better error messages.
This commit is contained in:
parent
4c287ba23e
commit
a82be1fbdb
setoolsgui/apol
@ -348,7 +348,7 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
|||||||
"({1}).".format(type(tab).__name__, settings["__tab__"]))
|
"({1}).".format(type(tab).__name__, settings["__tab__"]))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.AnalysisTabs.setTabText(index, settings["__title__"])
|
self.AnalysisTabs.setTabText(index, str(settings["__title__"]))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.log.warning("Settings file does not have a title setting.")
|
self.log.warning("Settings file does not have a title setting.")
|
||||||
|
|
||||||
@ -401,7 +401,8 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self.log.critical("Error loading settings file \"{0}\": {1}".format(filename, ex))
|
self.log.critical("Error loading settings file \"{0}\": {1}".format(filename, ex))
|
||||||
self.error_msg.critical(self, "Failed to load settings",
|
self.error_msg.critical(self, "Failed to load settings",
|
||||||
"Error loading settings file \"{0}\": {1}".format(filename, ex))
|
"Error loading settings file \"{0}\":\n\n{1}".
|
||||||
|
format(filename, ex))
|
||||||
else:
|
else:
|
||||||
self.log.info("Successfully loaded analysis settings from \"{0}\"".format(filename))
|
self.log.info("Successfully loaded analysis settings from \"{0}\"".format(filename))
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ def load_lineedits(tab, settings, lines):
|
|||||||
lineedit = getattr(tab, entry)
|
lineedit = getattr(tab, entry)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lineedit.setText(settings[entry])
|
lineedit.setText(str(settings[entry]))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning("{0} criteria missing from settings file.".format(entry))
|
log.warning("{0} criteria missing from settings file.".format(entry))
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ def load_textedits(tab, settings, edits):
|
|||||||
textedit = getattr(tab, entry)
|
textedit = getattr(tab, entry)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
textedit.setPlainText(settings[entry])
|
textedit.setPlainText(str(settings[entry]))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning("{0} criteria missing from settings file.".format(entry))
|
log.warning("{0} criteria missing from settings file.".format(entry))
|
||||||
|
|
||||||
@ -175,10 +175,14 @@ def load_listviews(tab, settings, listviews):
|
|||||||
# set list selections
|
# set list selections
|
||||||
for entry in listviews:
|
for entry in listviews:
|
||||||
try:
|
try:
|
||||||
selections = settings[entry]
|
selections = list(settings[entry])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning("{0} criteria missing from settings file.".format(entry))
|
log.warning("{0} criteria missing from settings file.".format(entry))
|
||||||
continue
|
continue
|
||||||
|
except TypeError:
|
||||||
|
msg = "Invalid list for {0} criteria: {1!r}".format(entry, settings[entry])
|
||||||
|
log.critical(msg)
|
||||||
|
raise TypeError(msg)
|
||||||
|
|
||||||
if not selections:
|
if not selections:
|
||||||
continue
|
continue
|
||||||
@ -225,7 +229,7 @@ def load_comboboxes(tab, settings, comboboxes):
|
|||||||
|
|
||||||
for entry in comboboxes:
|
for entry in comboboxes:
|
||||||
try:
|
try:
|
||||||
selection = settings[entry]
|
selection = str(settings[entry])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning("{0} criteria missing from settings file.".format(entry))
|
log.warning("{0} criteria missing from settings file.".format(entry))
|
||||||
continue
|
continue
|
||||||
@ -263,10 +267,14 @@ def load_spinboxes(tab, settings, spinboxes):
|
|||||||
|
|
||||||
for entry in spinboxes:
|
for entry in spinboxes:
|
||||||
try:
|
try:
|
||||||
value = settings[entry]
|
value = int(settings[entry])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.warning("{0} criteria missing from settings file.".format(entry))
|
log.warning("{0} criteria missing from settings file.".format(entry))
|
||||||
continue
|
continue
|
||||||
|
except (ValueError, TypeError) as ex:
|
||||||
|
msg = "Invalid value for {0} criteria: {1!r}.".format(entry, settings[entry])
|
||||||
|
log.critical(msg)
|
||||||
|
raise ex.__class__(msg)
|
||||||
|
|
||||||
spinbox = getattr(tab, entry)
|
spinbox = getattr(tab, entry)
|
||||||
spinbox.setValue(value)
|
spinbox.setValue(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user