Conversation
Running the following command currently fails:
ros2 topic pub --stdin /test std_msgs/Bool <<< "{data: true}"
The error is:
Traceback (most recent call last):
File "/python3.12-ros-jazzy-ros2cli-0.32.6-r1/bin/ros2", line 34, in <module>
sys.exit(load_entry_point('ros2cli==0.32.6', 'console_scripts', 'ros2')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/ros-env/lib/python3.12/site-packages/ros2cli/cli.py", line 91, in main
rc = extension.main(parser=parser, args=args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/ros-env/lib/python3.12/site-packages/ros2topic/command/topic.py", line 41, in main
return extension.main(args=args)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/ros-env/lib/python3.12/site-packages/ros2topic/verb/pub.py", line 117, in main
return main(args)
^^^^^^^^^^
File "/ros-env/lib/python3.12/site-packages/ros2topic/verb/pub.py", line 138, in main
return publisher(
^^^^^^^^^^
File "/ros-env/lib/python3.12/site-packages/ros2topic/verb/pub.py", line 174, in publisher
if '^J' in values:
^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'
We fix it by decoding stdin to utf8 string to match the type of values
passed via a command line argument.
Signed-off-by: Michal Sojka <michal.sojka@cvut.cz>
fujitatomoya
left a comment
There was a problem hiding this comment.
This allows subsequent code to work with a string instead of bytes, which is often necessary for text processing. test would be ideal to add somewhere like https://github.com/ros2/ros2cli/blob/rolling/ros2topic/test/test_echo_pub.py
|
I'm trying to write the test, but I have no idea how to pass something to process stdin. I see there is a Perhaps, I'd be able to write a test without the complex launch machinery by using plain Python's |
Description
Running the following command currently fails:
The error is:
We fix it by decoding stdin to utf8 string to match the type of values passed via a command line argument.
Is this user-facing behavior change?
yes
Did you use Generative AI?
no