diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index be39c1dc52b..503b45383c6 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -608,6 +608,11 @@ def _create_list_of_forward_model_steps_to_run( context=fm_step.name, ), ) + except Exception as e: # type: ignore + ConfigWarning.warn( + f"Unexpected plugin forward model exception: " f"{e!s}", + context=fm_step.name, + ) if errors: raise ConfigValidationError.from_collected(errors) diff --git a/tests/ert/unit_tests/config/test_forward_model.py b/tests/ert/unit_tests/config/test_forward_model.py index 401d7d4a016..8cf9178533f 100644 --- a/tests/ert/unit_tests/config/test_forward_model.py +++ b/tests/ert/unit_tests/config/test_forward_model.py @@ -952,3 +952,40 @@ def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: ErtConfig.with_plugins(forward_model_step_classes=[FM1]).from_file( tmp_path / "test.ert" ) + + +def test_that_plugin_forward_model_unexpected_errors_show_as_warnings(tmp_path): + (tmp_path / "test.ert").write_text( + """ + NUM_REALIZATIONS 1 + FORWARD_MODEL FMWithAssertionError(=never,=world,=derpyderp) + FORWARD_MODEL FMWithFMStepValidationError + """ + ) + + class FMWithAssertionError(ForwardModelStepPlugin): + def __init__(self): + super().__init__(name="FMWithAssertionError", command=["the_executable.sh"]) + + def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: + raise AssertionError("I should be a warning") + + class FMWithFMStepValidationError(ForwardModelStepPlugin): + def __init__(self): + super().__init__( + name="FMWithFMStepValidationError", + command=["the_executable.sh"], + ) + + def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None: + raise ForwardModelStepValidationError("I should not be a warning") + + with pytest.raises( + ConfigValidationError, match="I should not be a warning" + ), pytest.warns(ConfigWarning, match="I should be a warning"): + _ = ErtConfig.with_plugins( + forward_model_step_classes=[ + FMWithFMStepValidationError, + FMWithAssertionError, + ] + ).from_file(tmp_path / "test.ert")