Skip to content

Improve command arg type errors

Anton Joubert requested to merge improve-command-arg-type-errors into develop

Provide a more detailed error message if the user provides an argument with an invalid data type to a command.

Fixed a problem with DEV_STRING types, which were raising a SystemError instead of a TypeError due a missing check on the input argument before trying the conversion.

Fixed missing check in __get_tango_type utility. Unsupported types would raise UnboundLocalError, since r was not set. Added some tests for this, but note that the get_tango_type function isn't checking every element of the data structure, just the first. This is good enough for its normal usage, so no change required now.

Click to see example before change
>>> import tango
>>> dp = tango.DeviceProxy("sys/tg_test/1")
>>> dp.DevString([1, {"a": 2}])
TypeError: expected bytes, list found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/pytango/tango/device_proxy.py", line 365, in f
    return dp.command_inout(name, *args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/green.py", line 236, in greener
    return executor.run(fn, args, kwargs, wait=wait, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/green.py", line 126, in run
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/connection.py", line 116, in __Connection__command_inout
    r = Connection.command_inout_raw(self, name, *args, **kwds)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/connection.py", line 144, in __Connection__command_inout_raw
    param = __get_command_inout_param(self, cmd_name, cmd_param)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/connection.py", line 62, in __get_command_inout_param
    param.insert(info.in_type, cmd_param)
SystemError: <Boost.Python.function object at 0x600001f554a0> returned a result with an exception set
Click to see example after change
>>> import tango
>>> dp = tango.DeviceProxy("sys/tg_test/1")
>>> dp.DevString(["13", {}])
Traceback (most recent call last):
  File "/path/to/pytango/tango/connection.py", line 63, in __get_command_inout_param
    param.insert(info.in_type, cmd_param)
TypeError: can't translate python object to C char* in insert_scalar<Tango::DEV_STRING>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/pytango/tango/device_proxy.py", line 365, in f
    return dp.command_inout(name, *args, **kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/green.py", line 234, in greener
    return executor.run(fn, args, kwargs, wait=wait, timeout=timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/green.py", line 124, in run
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/connection.py", line 122, in __Connection__command_inout
    r = Connection.command_inout_raw(self, name, *args, **kwds)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/connection.py", line 150, in __Connection__command_inout_raw
    param = __get_command_inout_param(self, cmd_name, cmd_param)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pytango/tango/connection.py", line 65, in __get_command_inout_param
    raise TypeError(
TypeError: Invalid input argument for command DevString: ['13', {}] cannot be converted to type DevString

(Issue discovered while reviewing !657 (closed)).

Merge request reports

Loading