From 4e7269b4dfb537048ee4ca0a988d8b385efdf51b Mon Sep 17 00:00:00 2001 From: Daniel Goldberg Date: Sat, 9 Nov 2019 10:21:48 +0200 Subject: [PATCH] Exception handling whe building objects --- monkey/infection_monkey/utils/plugins/load_plugins.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/monkey/infection_monkey/utils/plugins/load_plugins.py b/monkey/infection_monkey/utils/plugins/load_plugins.py index 9a4faf771..0f39e70aa 100644 --- a/monkey/infection_monkey/utils/plugins/load_plugins.py +++ b/monkey/infection_monkey/utils/plugins/load_plugins.py @@ -35,8 +35,11 @@ def get_instances(base_package_name, base_package_file, parent_class: Plugin): # Get object from class for class_object in classes: LOG.debug("Checking if should run object {}".format(class_object.__name__)) - if class_object.should_run(class_object.__name__): - instance = class_object() - objects.append(instance) - LOG.debug("Added {} to list".format(class_object.__name__)) + try: + if class_object.should_run(class_object.__name__): + instance = class_object() + objects.append(instance) + LOG.debug("Added {} to list".format(class_object.__name__)) + except Exception as e: + LOG.warning("Exception {} when checking if {} should run".format(str(e), class_object.__name__)) return objects