Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better error message when passing an invalid value to ros2 topic pub #48

Merged
merged 1 commit into from
Sep 11, 2017

Conversation

dirk-thomas
Copy link
Member

@dirk-thomas dirk-thomas commented Sep 11, 2017

Instead of showing a stacktrace with the following exception:

AttributeError: 'str' object has no attribute 'items'

this patch prints an error message which includes an example value for the specified message type.

@dirk-thomas dirk-thomas added the in review Waiting for review (Kanban column) label Sep 11, 2017
@dirk-thomas dirk-thomas self-assigned this Sep 11, 2017
@dhood
Copy link
Member

dhood commented Sep 11, 2017

what message are you testing with? I don't know that this output is immediately useful?

$ ros2 topic pub /imu sensor_msgs/Imu 5
The passed value needs to be a dictionary in YAML format, e.g.:
!!python/object/apply:collections.OrderedDict
- - - header
    - !!python/object/apply:collections.OrderedDict
      - - - stamp
          - !!python/object/apply:collections.OrderedDict
            - - [sec, 0]
              - [nanosec, 0]
        - [frame_id, '']
  - - orientation
    - !!python/object/apply:collections.OrderedDict
      - - [x, 0.0]
        - [y, 0.0]
        - [z, 0.0]
        - [w, 0.0]
  - - orientation_covariance
    - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
  - - angular_velocity
    - !!python/object/apply:collections.OrderedDict
      - - [x, 0.0]
        - [y, 0.0]
        - [z, 0.0]
  - - angular_velocity_covariance
    - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
  - - linear_acceleration
    - !!python/object/apply:collections.OrderedDict
      - - [x, 0.0]
        - [y, 0.0]
        - [z, 0.0]
  - - linear_acceleration_covariance
    - [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

@dirk-thomas
Copy link
Member Author

dirk-thomas commented Sep 11, 2017

I only tried a std_msgs/String message. For that the output looked much saner 😉

I will put it back in progress for now. It can be updated after Beta 3.

@dirk-thomas dirk-thomas added in progress Actively being worked on (Kanban column) and removed in review Waiting for review (Kanban column) labels Sep 11, 2017
@mikaelarguedas
Copy link
Member

If we iterate on this after beta3 maybe working on providing autocomplete ala ros1 for the message in yaml would workaround this issue while providing better user experience

@dirk-thomas
Copy link
Member Author

I updated this for now to just give a reasonable error message. An example of a valid value and/or completion can be done in the future to further improve the user experience.

Back in review.

@dirk-thomas dirk-thomas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Sep 11, 2017
@@ -66,6 +66,8 @@ def publisher(message_type, topic_name, values):
module = importlib.import_module(package_name + '.msg')
msg_module = getattr(module, message_name)
values_dictionary = yaml.load(values)
if not isinstance(values_dictionary, dict):
return 'The passed value needs to be a dictionary in YAML format'
Copy link
Member

@dhood dhood Sep 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come it's appropriate to return the error message here instead of raise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the return value of this function is also the return value of main.

A few lines below (line 82) it does the same.

@mikaelarguedas
Copy link
Member

Should the help message be updated to use the dictionary notation ?
Right now if we copy past the value from the help this message is returned

@dirk-thomas
Copy link
Member Author

Right now if we copy past the value from the help this message is returned

Can you please post the exact command you are invoking. For me the following command (as suggested by the help text) does work fine:

ros2 topic pub /chatter std_msgs/String "data: Hello World"

@mikaelarguedas
Copy link
Member

Nvm I was missing a space because of the line break in the help...
ros2 topic pub /chatter std_msgs/String "data:Hello World" fails but
ros2 topic pub /chatter std_msgs/String "data: Hello World" works

If taking a slightly more complex example:
ros2 topic pub /chatter test_msgs/DynamicArrayPrimitives "bool_values:[True, False]" fails but
ros2 topic pub /chatter test_msgs/DynamicArrayPrimitives "{bool_values: [True, False]}" passes. That's why I thought we needed a dictionary notation.

I guess we just need to make sure people don't forget to add a space between each key / value

Copy link
Member

@mikaelarguedas mikaelarguedas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dirk-thomas dirk-thomas merged commit 5540f2c into master Sep 11, 2017
@dirk-thomas dirk-thomas deleted the improve_error_message branch September 11, 2017 23:40
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label Sep 11, 2017
esteve pushed a commit to esteve/ros2cli that referenced this pull request Dec 16, 2022
ensure terminating subprocesses on keyboard interrupt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants