Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn unexpected fm errors into warnings #8832

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")