openturns / otfmi

FMI models manipulation module
http://openturns.github.io/otfmi/master/
GNU Lesser General Public License v3.0
8 stars 9 forks source link

Confusing error message #85

Closed Claire-Eleutheriane closed 2 years ago

Claire-Eleutheriane commented 2 years ago

Issue description

otfmi.fmi.get_name_variable takes as argument a model which is either a Pyfmi object or a string.

A newcomer to OTFMI may write the following code (as it makes sense):

model = otfmi.FMUFunction(path_fmu, ...)
list_name = otfmi.fmi.get_name_variable(model)

The following error message appears (as model is an overlay of a FMUFunction, not a Pyfmi object):

Traceback (most recent call last):
  File "/home/gerrer/Desktop/test_otfmi/pi_fail.py", line 15, in <module>
    otfmi.fmi.get_name_variable(func)
  File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/site-packages/otfmi/fmi.py", line 331, in get_name_variable
    model = load_fmu(model)
  File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/site-packages/otfmi/fmi.py", line 36, in load_fmu
    return pyfmi.load_fmu(path_fmu, kind="CS", log_file_name=log_file_name)
  File "src/pyfmi/fmi.pyx", line 8588, in pyfmi.fmi.load_fmu
  File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/posixpath.py", line 90, in join
    genericpath._check_arg_types('join', a, *p)
  File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/genericpath.py", line 152, in _check_arg_types
    raise TypeError(f'{funcname}() argument must be str, bytes, or '
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'Function'

Potential solution

In otfmi/fmi.py, lines 465 : replace the type test performed by "try - except" with condition on the accessibility of a method by a real type test (is instance of pyfmi object or string) and clear error message if this is not the case.