Skip to content

Commit 18320c6

Browse files
committed
Add error catching for mod loaders
1 parent 46fa9cb commit 18320c6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

ModFiles/Detection.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def install_mod_in_manager(mod_source_path, install_path, mbe_unpack):
189189
else:
190190
raise UnrecognisedModFormatError()
191191

192-
def detect_mods(path):
192+
def detect_mods(path, log):
193193
"""Check for qualifying mods in the registered mods folder."""
194194
dirpath = os.path.join(path, "mods")
195195
os.makedirs(dirpath, exist_ok=True)
@@ -199,11 +199,19 @@ def detect_mods(path):
199199
itempath = os.path.join(dirpath, item)
200200
modtype = LooseMod
201201
if modtype.check_if_match(itempath):
202-
mod_obj = modtype(itempath)
202+
try:
203+
mod_obj = modtype(itempath)
204+
except json.decoder.JSONDecodeError as e:
205+
log(f"An error occured when reading {item}/METADATA.json: {e}")
206+
continue
203207
# If the mod has a wizard defined, attach it for reinstallation purposes
204-
wizard = check_installer_type(itempath)
205-
if wizard is not None:
206-
mod_obj.wizard = wizard
208+
try:
209+
wizard = check_installer_type(itempath)
210+
if wizard is not None:
211+
mod_obj.wizard = wizard
212+
except json.decoder.JSONDecodeError as e:
213+
log(f"An error occured when reading INSTALL.json for {mod_obj.name}: {e}")
214+
continue
207215
detected_mods.append(mod_obj)
208216
return detected_mods
209217

SimpleDSCSModManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def compile_scripts(self):
395395
############################################
396396
def update_mods(self):
397397
try:
398-
self.mods = detect_mods(script_loc)
398+
self.mods = detect_mods(script_loc, self.ui.log)
399399
except Exception as e:
400400
self.ui.log(f"An unknown error occured during mod detection: {e}")
401401
self.modpath_to_id = {mod.path: i for i, mod in enumerate(self.mods)}

0 commit comments

Comments
 (0)