Skip to content

Commit 65cd1cf

Browse files
authored
Merge pull request #116 from jakzie2/develop
Startup exceptions show a name of the mod causing them
2 parents 6b95597 + 80cffbb commit 65cd1cf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

modloader/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ def update_command():
9696
update_modtools(args.url)
9797

9898

99+
def mod_error_check(func, mod_name, phase):
100+
"""Reraise an exception with a name of the mod and its original traceback"""
101+
try:
102+
return func(mod_name)
103+
except Exception as e:
104+
original_msg = " " + type(e).__name__ + ": " + "\n ".join(e.message.split("\n"))
105+
msg = "\nAn error occured while " + phase + " the mod \"" + mod_name + "\":\n\n" + original_msg + "\n\nPlease report this issue to the author of this mod."
106+
raise Exception, Exception(msg), sys.exc_info()[2]
107+
108+
99109
def resolve_dependencies():
100110
"""Resolve mod dependencies and create mod load order"""
101111
from modloader import modinfo
@@ -214,7 +224,7 @@ def main(reload_mods=False):
214224
# Try importing the mod.
215225
# Note: This doesn't give my mod functionality. To give the mod
216226
# function, make a Mod class and apply the loadable_mod decorator
217-
mod_object = importlib.import_module(mod)
227+
mod_object = mod_error_check(importlib.import_module, mod, "importing")
218228
if reload_mods:
219229
rreload(mod_object, modules)
220230

@@ -232,12 +242,12 @@ def main(reload_mods=False):
232242
# Then loop through the mods in their load order and call their respective mod_load functions
233243
for mod_name in modinfo.mod_load_order:
234244
print "Loading mod {}".format(mod_name)
235-
modinfo.get_mod(mod_name).mod_load()
245+
mod_error_check(lambda n: modinfo.get_mod(n).mod_load(), mod_name, "loading")
236246

237247
# After all mods are loaded, call their respective mod_complete functions
238248
for mod_name in modinfo.mod_load_order:
239249
print "Completing mod {}".format(mod_name)
240-
modinfo.get_mod(mod_name).mod_complete()
250+
mod_error_check(lambda n: modinfo.get_mod(n).mod_complete(), mod_name, "completing")
241251

242252
# Force renpy to reindex all game files
243253
renpy.loader.old_config_archives = None

0 commit comments

Comments
 (0)