1818
1919from OMPython .model_execution import (
2020 ModelExecutionCmd ,
21+ ModelExecutionException ,
2122)
2223from OMPython .om_session_abc import (
2324 OMPathABC ,
@@ -200,7 +201,10 @@ def check_model_executable(self):
200201 # ... by running it - output help for command help
201202 om_cmd .arg_set (key = "help" , val = "help" )
202203 cmd_definition = om_cmd .definition ()
203- returncode = cmd_definition .run ()
204+ try :
205+ returncode = cmd_definition .run ()
206+ except ModelExecutionException as exc :
207+ raise ModelicaSystemError (f"Cannot execute model: { exc } " ) from exc
204208 if returncode != 0 :
205209 raise ModelicaSystemError ("Model executable not working!" )
206210
@@ -736,7 +740,10 @@ def simulate(
736740 self ._result_file .unlink ()
737741 # ... run simulation ...
738742 cmd_definition = om_cmd .definition ()
739- returncode = cmd_definition .run ()
743+ try :
744+ returncode = cmd_definition .run ()
745+ except ModelExecutionException as exc :
746+ raise ModelicaSystemError (f"Cannot execute model: { exc } " ) from exc
740747 # and check returncode *AND* resultfile
741748 if returncode != 0 and self ._result_file .is_file ():
742749 # check for an empty (=> 0B) result file which indicates a crash of the model executable
@@ -764,8 +771,10 @@ def prepare_str(str_in: str) -> dict[str, str]:
764771 key_val_list : list [str ] = str_in .split ("=" )
765772 if len (key_val_list ) != 2 :
766773 raise ModelicaSystemError (f"Invalid 'key=value' pair: { str_in } " )
774+ if len (key_val_list [0 ]) == 0 :
775+ raise ModelicaSystemError (f"Empty key: { str_in } " )
767776
768- input_data_from_str : dict [str , str ] = {key_val_list [0 ]: key_val_list [1 ]}
777+ input_data_from_str : dict [str , str ] = {str ( key_val_list [0 ]): str ( key_val_list [1 ]) }
769778
770779 return input_data_from_str
771780
@@ -791,7 +800,12 @@ def prepare_str(str_in: str) -> dict[str, str]:
791800 raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (item )} !" )
792801 input_data = input_data | prepare_str (item )
793802 elif isinstance (input_arg , dict ):
794- input_data = input_data | input_arg
803+ input_arg_str : dict [str , str ] = {}
804+ for key , val in input_arg .items ():
805+ if not isinstance (key , str ) or len (key ) == 0 :
806+ raise ModelicaSystemError (f"Invalid key for set*() functions: { repr (key )} " )
807+ input_arg_str [key ] = str (val )
808+ input_data = input_data | input_arg_str
795809 else :
796810 raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (input_arg )} !" )
797811
@@ -1180,7 +1194,10 @@ def linearize(
11801194 linear_file .unlink (missing_ok = True )
11811195
11821196 cmd_definition = om_cmd .definition ()
1183- returncode = cmd_definition .run ()
1197+ try :
1198+ returncode = cmd_definition .run ()
1199+ except ModelExecutionException as exc :
1200+ raise ModelicaSystemError (f"Cannot execute model: { exc } " ) from exc
11841201 if returncode != 0 :
11851202 raise ModelicaSystemError (f"Linearize failed with return code: { returncode } " )
11861203 if not linear_file .is_file ():
0 commit comments