1818
1919from OMPython .model_execution import (
2020 ModelExecutionCmd ,
21+ ModelExecutionException ,
2122)
2223from OMPython .om_session_abc import (
2324 OMPathABC ,
@@ -199,7 +200,10 @@ def check_model_executable(self):
199200 # ... by running it - output help for command help
200201 om_cmd .arg_set (key = "help" , val = "help" )
201202 cmd_definition = om_cmd .definition ()
202- returncode = cmd_definition .run ()
203+ try :
204+ returncode = cmd_definition .run ()
205+ except ModelExecutionException as exc :
206+ raise ModelicaSystemError (f"Cannot execute model: { exc } " ) from exc
203207 if returncode != 0 :
204208 raise ModelicaSystemError ("Model executable not working!" )
205209
@@ -730,7 +734,10 @@ def simulate(
730734 self ._result_file .unlink ()
731735 # ... run simulation ...
732736 cmd_definition = om_cmd .definition ()
733- returncode = cmd_definition .run ()
737+ try :
738+ returncode = cmd_definition .run ()
739+ except ModelExecutionException as exc :
740+ raise ModelicaSystemError (f"Cannot execute model: { exc } " ) from exc
734741 # and check returncode *AND* resultfile
735742 if returncode != 0 and self ._result_file .is_file ():
736743 # check for an empty (=> 0B) result file which indicates a crash of the model executable
@@ -758,8 +765,10 @@ def prepare_str(str_in: str) -> dict[str, str]:
758765 key_val_list : list [str ] = str_in .split ("=" )
759766 if len (key_val_list ) != 2 :
760767 raise ModelicaSystemError (f"Invalid 'key=value' pair: { str_in } " )
768+ if len (key_val_list [0 ]) == 0 :
769+ raise ModelicaSystemError (f"Empty key: { str_in } " )
761770
762- input_data_from_str : dict [str , str ] = {key_val_list [0 ]: key_val_list [1 ]}
771+ input_data_from_str : dict [str , str ] = {str ( key_val_list [0 ]): str ( key_val_list [1 ]) }
763772
764773 return input_data_from_str
765774
@@ -785,7 +794,12 @@ def prepare_str(str_in: str) -> dict[str, str]:
785794 raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (item )} !" )
786795 input_data = input_data | prepare_str (item )
787796 elif isinstance (input_arg , dict ):
788- input_data = input_data | input_arg
797+ input_arg_str : dict [str , str ] = {}
798+ for key , val in input_arg .items ():
799+ if not isinstance (key , str ) or len (key ) == 0 :
800+ raise ModelicaSystemError (f"Invalid key for set*() functions: { repr (key )} " )
801+ input_arg_str [key ] = str (val )
802+ input_data = input_data | input_arg_str
789803 else :
790804 raise ModelicaSystemError (f"Invalid input data type for set*() function: { type (input_arg )} !" )
791805
@@ -1173,7 +1187,10 @@ def linearize(
11731187 linear_file .unlink (missing_ok = True )
11741188
11751189 cmd_definition = om_cmd .definition ()
1176- returncode = cmd_definition .run ()
1190+ try :
1191+ returncode = cmd_definition .run ()
1192+ except ModelExecutionException as exc :
1193+ raise ModelicaSystemError (f"Cannot execute model: { exc } " ) from exc
11771194 if returncode != 0 :
11781195 raise ModelicaSystemError (f"Linearize failed with return code: { returncode } " )
11791196 if not linear_file .is_file ():
0 commit comments