Skip to content

Commit 737aed5

Browse files
committed
gui_settings.py: Add error handling for invalid value
1 parent 868cfa6 commit 737aed5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

opencore_legacy_patcher/wx_gui/gui_settings.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,16 @@ def _generate_elements(self, frame: wx.Frame = None) -> None:
158158
if setting_info["type"] == "checkbox":
159159
# Add checkbox, and description underneath
160160
checkbox = wx.CheckBox(panel, label=setting, pos=(10 + width, 10 + height), size = (300,-1))
161-
checkbox.SetValue(setting_info["value"] if setting_info["value"] else False)
161+
162+
value = False
163+
if "value" in setting_info:
164+
try:
165+
value = bool(setting_info["value"])
166+
except ValueError:
167+
logging.error(f"Invalid value for {setting}, got {setting_info['value']} (type: {type(setting_info['value'])})")
168+
value = False
169+
170+
checkbox.SetValue(value)
162171
checkbox.SetFont(gui_support.font_factory(13, wx.FONTWEIGHT_BOLD))
163172
event = lambda event, warning=setting_info["warning"] if "warning" in setting_info else "", override=bool(setting_info["override_function"]) if "override_function" in setting_info else False: self.on_checkbox(event, warning, override)
164173
checkbox.Bind(wx.EVT_CHECKBOX, event)

0 commit comments

Comments
 (0)