RobotWebTools / ros2-web-bridge

Bridging your browser to the ROS 2.0
Apache License 2.0
203 stars 68 forks source link

Use clearer error message when publishing without first advertising #163

Closed christophebedard closed 3 years ago

christophebedard commented 3 years ago

I'm new to ros2-web-bridge and its protocol, so it took me some time to understand that this is what happens when you try to publish without first advertising the topic and its type:

ros2-web-bridge:Bridge JSON command received: {"op":"publish","id":"publish:/example_topic2:1","topic":"/example_topic2","msg":{"data":"hello"},"latch":false} +11s
  ros2-web-bridge:Bridge Publish a topic named /example_topic2 with {"data":"hello"} +0ms
  ros2-web-bridge:Bridge Response: {"op":"status","level":"error","msg":"publish: TypeError: Cannot read property 'get' of undefined","id":"publish:/example_topic2:1"} +1ms

This PR adds a clearer error message (similar to what the other ops have):

  ros2-web-bridge:Bridge JSON command received: {"op":"publish","id":"publish:/example_topic2:1","topic":"/example_topic2","msg":{"data":"hello"},"latch":false} +2s
  ros2-web-bridge:Bridge Publish a topic named /example_topic2 with {"data":"hello"} +1ms
  ros2-web-bridge:Bridge Response: {"op":"status","level":"error","msg":"publish: Error: The topic /example_topic2 does not exist","id":"publish:/example_topic2:1"} +1ms