diff --git a/force_bdss/core_evaluation_driver.py b/force_bdss/core_evaluation_driver.py index e10851c20d8849c78073c0ca642ce4d0c3a5aaf1..498fc0ca10b74a10754a3109b14d79cfa37f420d 100644 --- a/force_bdss/core_evaluation_driver.py +++ b/force_bdss/core_evaluation_driver.py @@ -31,7 +31,15 @@ class CoreEvaluationDriver(BaseCoreDriver): mco_factory = mco_model.factory log.info("Creating communicator") - mco_communicator = mco_factory.create_communicator() + try: + mco_communicator = mco_factory.create_communicator() + except Exception: + log.exception( + "Unable to create communicator from MCO factory '{}' " + "in plugin '{}'. This may indicate a programming " + "error in the plugin".format( + mco_factory.get_identifier(), + mco_factory.plugin.id)) mco_data_values = _get_data_values_from_mco( mco_model, mco_communicator) @@ -85,7 +93,16 @@ def _compute_layer_results(environment_data_values, for model in layer.data_sources: factory = model.factory - data_source = factory.create_data_source() + try: + data_source = factory.create_data_source() + except Exception: + log.exception( + "Unable to create data source from factory '{}' " + "in plugin '{}'. This may indicate a programming " + "error in the plugin".format( + factory.get_identifier(), + factory.plugin.id)) + raise # Get the slots for this data source. These must be matched to # the appropriate values in the environment data values. @@ -111,8 +128,9 @@ def _compute_layer_results(environment_data_values, try: res = data_source.run(model, passed_data_values) except Exception: - log.error("Evaluation could not be performed. Run method raised" - "exception", exc_info=True) + log.exception( + "Evaluation could not be performed. " + "Run method raised exception.") raise if len(res) != len(out_slots): diff --git a/force_bdss/core_mco_driver.py b/force_bdss/core_mco_driver.py index 9e8bc98f41b78ff6f05d79a18b2a298af40a75f4..6dfde5502f46240156e931cec7c6e71107b15b7d 100644 --- a/force_bdss/core_mco_driver.py +++ b/force_bdss/core_mco_driver.py @@ -8,10 +8,6 @@ from force_bdss.mco.base_mco import BaseMCO from force_bdss.notification_listeners.base_notification_listener import \ BaseNotificationListener from .base_core_driver import BaseCoreDriver -from .io.workflow_reader import ( - InvalidVersionException, - InvalidFileException -) from .core_driver_events import MCOStartEvent, MCOFinishEvent, MCOProgressEvent log = logging.getLogger(__name__) @@ -40,8 +36,8 @@ class CoreMCODriver(BaseCoreDriver): def _mco_default(self): try: workflow = self.workflow - except (InvalidVersionException, InvalidFileException) as e: - log.exception(e) + except Exception: + log.exception("Unable to open workflow file.") sys.exit(1) mco_model = workflow.mco @@ -50,7 +46,18 @@ class CoreMCODriver(BaseCoreDriver): sys.exit(0) mco_factory = mco_model.factory - return mco_factory.create_optimizer() + try: + optimizer = mco_factory.create_optimizer() + except Exception: + factory_id = mco_factory.id, + plugin_id = mco_factory.plugin.id + log.exception("Unable to instantiate optimizer for mco '{}' in " + "plugin '{}'. An exception was raised. " + "This might indicate a programming error in the " + "plugin.".format(factory_id, plugin_id)) + raise + + return optimizer @on_trait_change("mco:started") def _deliver_start_event(self): @@ -80,11 +87,13 @@ class CoreMCODriver(BaseCoreDriver): for listener in self.listeners[:]: try: listener.deliver(event) - except Exception as e: - log.error( - "Exception while delivering to listener {}: {}".format( - listener.__class__.__name__, - str(e) + except Exception: + log.exception( + "Exception while delivering to listener " + "'{}' in plugin '{}'. The listener will be dropped and " + "computation will continue.".format( + listener.factory.id, + listener.factory.plugin.id )) self._finalize_listener(listener) self.listeners.remove(listener) @@ -96,14 +105,30 @@ class CoreMCODriver(BaseCoreDriver): factory = nl_model.factory try: listener = factory.create_listener() + except Exception: + log.exception( + "Failed to create listener with id '{}' in plugin '{}'. " + "This may indicate a programming error in the " + "plugin.".format( + factory.id, + factory.plugin.id + ) + ) + raise + + try: listener.initialize(nl_model) - except Exception as e: - log.error( - "Failed to create or initialize " - "listener with id {}: {}".format( - factory.id, str(e))) - else: - listeners.append(listener) + except Exception: + log.exception( + "Failed to initialize listener with id '{}' in " + "plugin '{}'. The listener will be dropped.".format( + factory.id, + factory.plugin.id + ) + ) + continue + + listeners.append(listener) return listeners @@ -114,9 +139,10 @@ class CoreMCODriver(BaseCoreDriver): """ try: listener.finalize() - except Exception as e: - log.error( - "Exception while finalizing listener {}: {}".format( - listener.__class__.__name__, - str(e) + except Exception: + log.exception( + "Exception while finalizing listener '{}'" + " in plugin '{}'.".format( + listener.factory.id, + listener.factory.plugin.id )) diff --git a/force_bdss/tests/test_core_mco_driver.py b/force_bdss/tests/test_core_mco_driver.py index d14fbfe4785cf22d948b129a7b6c0642aede370d..407244e3fdedf9c002fa88ab43a52c0e54988002 100644 --- a/force_bdss/tests/test_core_mco_driver.py +++ b/force_bdss/tests/test_core_mco_driver.py @@ -91,9 +91,11 @@ class TestCoreMCODriver(unittest.TestCase): capture.check( ("force_bdss.core_mco_driver", "ERROR", - "Failed to create or initialize listener with id " - "force.bdss.enthought.plugin.test.v0" - ".factory.probe_notification_listener: ")) + "Failed to initialize listener with id " + "'force.bdss.enthought.plugin.test.v0" + ".factory.probe_notification_listener' in plugin " + "'force.bdss.enthought.plugin.test.v0'. " + "The listener will be dropped.")) self.assertEqual(len(listeners), 0) @@ -111,7 +113,10 @@ class TestCoreMCODriver(unittest.TestCase): ("force_bdss.core_mco_driver", "ERROR", "Exception while delivering to listener " - "ProbeNotificationListener: ")) + "'force.bdss.enthought.plugin.test.v0" + ".factory.probe_notification_listener' in plugin " + "'force.bdss.enthought.plugin.test.v0'. The listener will " + "be dropped and computation will continue." )) def test_finalize_error(self): driver = CoreMCODriver( @@ -127,4 +132,6 @@ class TestCoreMCODriver(unittest.TestCase): ("force_bdss.core_mco_driver", "ERROR", "Exception while finalizing listener " - "ProbeNotificationListener: ")) + "'force.bdss.enthought.plugin.test.v0" + ".factory.probe_notification_listener' in plugin " + "'force.bdss.enthought.plugin.test.v0'."))