From d4be945dde9bfbfeadd396d500a34c86a06379ec Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 2 Apr 2024 12:38:14 +1100 Subject: [PATCH] fix(nodes): gracefully handle custom nodes init error Previously, exceptions raised as custom nodes are initialized were fatal errors, causing the app to exit. With this change, any error on import is caught and the error message printed. App continues to start up without the node. For example, a custom node that isn't updated for v4.0.0 may raise an error on import if it is attempting to import things that no longer exist. --- invokeai/app/invocations/custom_nodes/init.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/invokeai/app/invocations/custom_nodes/init.py b/invokeai/app/invocations/custom_nodes/init.py index e0c174013f..efddede72f 100644 --- a/invokeai/app/invocations/custom_nodes/init.py +++ b/invokeai/app/invocations/custom_nodes/init.py @@ -3,6 +3,7 @@ Invoke-managed custom node loader. See README.md for more information. """ import sys +import traceback from importlib.util import module_from_spec, spec_from_file_location from pathlib import Path @@ -41,11 +42,15 @@ for d in Path(__file__).parent.iterdir(): logger.info(f"Loading node pack {module_name}") - module = module_from_spec(spec) - sys.modules[spec.name] = module - spec.loader.exec_module(module) + try: + module = module_from_spec(spec) + sys.modules[spec.name] = module + spec.loader.exec_module(module) - loaded_count += 1 + loaded_count += 1 + except Exception: + full_error = traceback.format_exc() + logger.error(f"Failed to load node pack {module_name}:\n{full_error}") del init, module_name