Skip to content

Commit

Permalink
Turn unexpected fm errors into warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk authored Oct 2, 2024
1 parent ad8bfc4 commit 5d4205d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions tests/ert/unit_tests/config/test_forward_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(<arg1>=never,<arg2>=world,<arg3>=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")

0 comments on commit 5d4205d

Please sign in to comment.