aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-09-03 19:59:11 +0300
committerAUTOMATIC <16777216c@gmail.com>2022-09-03 19:59:11 +0300
commite67a56dbb4643c7ddd01668bcd7c4ec7f58f7d81 (patch)
tree39cee5fda2ab394f2a42bddfe63228486c81fd49
parent226de5e503574458e02d433eba28c689b838d953 (diff)
fix to make scripts that failed to compile not crash the program
-rw-r--r--modules/scripts.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/modules/scripts.py b/modules/scripts.py
index 37a23682..99502857 100644
--- a/modules/scripts.py
+++ b/modules/scripts.py
@@ -41,17 +41,21 @@ def load_scripts(basedir):
with open(path, "r", encoding="utf8") as file:
text = file.read()
- from types import ModuleType
- compiled = compile(text, path, 'exec')
- module = ModuleType(filename)
- exec(compiled, module.__dict__)
-
- for key, script_class in module.__dict__.items():
- if type(script_class) == type and issubclass(script_class, Script):
- obj = script_class()
- obj.filename = path
-
- scripts.append(obj)
+ try:
+ from types import ModuleType
+ compiled = compile(text, path, 'exec')
+ module = ModuleType(filename)
+ exec(compiled, module.__dict__)
+
+ for key, script_class in module.__dict__.items():
+ if type(script_class) == type and issubclass(script_class, Script):
+ obj = script_class()
+ obj.filename = path
+
+ scripts.append(obj)
+ except Exception:
+ print(f"Error loading script: {filename}", file=sys.stderr)
+ print(traceback.format_exc(), file=sys.stderr)
def wrap_call(func, filename, funcname, *args, default=None, **kwargs):