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

Make sure to check errors when expanding the topic name. #58

Merged
merged 2 commits into from
Oct 11, 2017

Conversation

clalancette
Copy link
Contributor

We need to catch ValueErrors when actually doing the expansion,
then InvalidTopicNameException when doing the validation.

Signed-off-by: Chris Lalancette clalancette@openrobotics.org

We need to catch ValueErrors when actually doing the expansion,
then InvalidTopicNameException when doing the validation.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette clalancette added the in progress Actively being worked on (Kanban column) label Oct 5, 2017
try:
expanded_name = expand_topic_name(topic_name, node.get_name(), node.get_namespace())
except ValueError as e:
raise RuntimeError("Topic name '%s' is invalid" % (topic_name))
Copy link
Member

Choose a reason for hiding this comment

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

The docblock of the function says the following which doesn't seem to match the error message:

:raises: ValueError if the topic name, node name or namespace are invalid

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this RuntimeError get handled elsewhere, or does the user see the RuntimeError traceback? If the latter it looks like the ValueError raised by rclpy already includes a similar message. How about writing that message, e.args[0], to stderr instead?

https://github.com/ros2/rclpy/blob/a6daedbde500a1dbd222c1f1851e1ae2aea1f2e1/rclpy/src/rclpy/_rclpy.c#L519-L520

Copy link
Member

@dirk-thomas dirk-thomas Oct 5, 2017

Choose a reason for hiding this comment

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

The RuntimeError is being used to signal an error where the user only needs to see the message but not the stack trace: see

except RuntimeError as e:
rc = str(e)
return rc

By handling this in a single place it allows to easily change the behavior in the future. That would not be the case if every code directly decides what to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A RuntimeError gets handled by the higher layers of ros2cli and prints out a nice error message. My original implementation here did what @sloretz proposed, but the problem is that the error message it actually generates is kind of ugly:

topic name '/test_topic/' is invalid: topic name is invalid, at /home/clalancette/ros2_ws/src/ros2/rcl/rcl/src/rcl/expand_topic_name.c:67

That being said, if we think that is a better way to go, I'll change it to that.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @dirk-thomas that the value error doesn't imply topic is bad only. Other than that I think the runtime error pattern is fine.

If you want to make the error message pretty then you can reformat it when putting it into the runtime error. Or if it's a general improvement to the error message, you could make it in rclpy's function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All right, I updated this to use the original exception instead. I'll do a more general cleanup to that error message in another PR.

Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
@clalancette clalancette added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Oct 6, 2017
@clalancette
Copy link
Contributor Author

Thanks, merging.

@clalancette clalancette merged commit 2409d8b into master Oct 11, 2017
@clalancette clalancette removed the in review Waiting for review (Kanban column) label Oct 11, 2017
@clalancette clalancette deleted the echo-catch-expansion-errors branch October 11, 2017 19:40
esteve pushed a commit to esteve/ros2cli that referenced this pull request Dec 16, 2022
suppress repeated SIGINTs in order to cleanly shutdown
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.

4 participants