diff --git a/khiops/core/internals/runner.py b/khiops/core/internals/runner.py index 7262bd28..0191e99a 100644 --- a/khiops/core/internals/runner.py +++ b/khiops/core/internals/runner.py @@ -746,6 +746,13 @@ def _report_exit_status( f"Khiops ended correctly but there were minor issues:\n{error_msg}" ) warnings.warn(error_msg.rstrip()) + else: + # no message available, an error must be raised though + if return_code != 0: + raise KhiopsRuntimeError( + f"{tool_name} execution had errors (return code {return_code}) " + "but no message is available\n" + ) def _collect_errors(self, log_file_path): # Collect errors any errors found in the log diff --git a/tests/test_core.py b/tests/test_core.py index 9fc3dcde..f684739d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -18,6 +18,7 @@ import khiops import khiops.core as kh +from khiops.core import KhiopsRuntimeError from khiops.core.internals.common import create_unambiguous_khiops_path from khiops.core.internals.io import KhiopsOutputWriter from khiops.core.internals.runner import KhiopsLocalRunner, KhiopsRunner @@ -2691,6 +2692,24 @@ def test_khiops_environment_variables_basic(self): else: os.environ[fixture["variable"]] = old_value + def test_raise_exception_on_error_case_without_a_message(self): + with self.assertRaises(KhiopsRuntimeError): + with MockedRunnerContext( + create_mocked_raw_run( + False, # ask for an empty stdout + False, # ask for an empty stderr + 9, # non-zero error code + ) + ): + kh.train_predictor( + "/tmp/Iris.kdic", + dictionary_name="Iris", + data_table_path="/tmp/Iris.txt", + target_variable="Class", + results_dir="/tmp", + trace=True, + ) + if __name__ == "__main__": unittest.main()