Conversation
|
Rebased on master |
cottsay
left a comment
There was a problem hiding this comment.
A few quick comments to address.
It's worth noting that several of the return types are changing from List to Tuple in this PR, though it's probably the right thing to do since it matches the documentation and is more performant.
rclpy/src/rclpy/names.cpp
Outdated
| if (rcutils_ret == RCUTILS_RET_BAD_ALLOC) { | ||
| rcl_reset_error(); | ||
| throw std::bad_alloc(); | ||
| } else if (rcutils_ret != RCUTILS_RET_OK) { | ||
| throw RCLError("failed to initialize string map"); | ||
| } |
There was a problem hiding this comment.
This should be rcutils error handling, not rcl.
There was a problem hiding this comment.
The docs should be updated to reflect the other exception type, too.
There was a problem hiding this comment.
Updated docs with RMWError, RCUtilsError, or RCLError in c269b6a
There was a problem hiding this comment.
Oops, actually fixed this one in d7fd3b0
rclpy/src/rclpy/names.hpp
Outdated
| /// Validate a node name and return error message and index of invalidation. | ||
| /** | ||
| * Raises MemoryError if memory could not be allocated | ||
| * Raises RuntimeError if an unexpected error happened while validating the node name |
There was a problem hiding this comment.
| * Raises RuntimeError if an unexpected error happened while validating the node name | |
| * Raises RCLError if an unexpected error happened while validating the node name |
There was a problem hiding this comment.
I think this doc got fixed in c269b6a too
|
|
||
| /// Expand a topic name | ||
| /** | ||
| * Raises ValueError if the topic name, node name, or namespace are not valid. |
There was a problem hiding this comment.
These last three functions can raise RCLError. Is that omitted intentionally?
There was a problem hiding this comment.
Added note about raising RCLError in c269b6a
rclpy/src/rclpy/names.cpp
Outdated
| int validation_result; | ||
| size_t invalid_index; | ||
| rmw_ret_t ret = rmw_validate_namespace(namespace_, &validation_result, &invalid_index); | ||
| if (ret == RCL_RET_BAD_ALLOC) { |
There was a problem hiding this comment.
I think there a similar issue in get_validation_error_for_full_topic_name, get_validation_error_for_node_name.
On further investigation, there seems to be some handling for this in rcl. They seem to be translated to rcl error codes though?
https://github.com/ros2/rcl/blob/0ca8c6162136594e490ba69fbf288de1b5f7073d/rcl/src/rcl/expand_topic_name.c#L79
There was a problem hiding this comment.
Both rmw and rcl error handling APIs are aliases of rcutils'. That's why people tend to use them interchangeably. Which means we'll have a huge body of code to migrate if that stops being true at some point.
There was a problem hiding this comment.
Regardless, I think it is worthwhile to use the correct types (even if they are aliases of each other). Besides the fact that it makes migration possible (though that is unlikely), there is no question for future readers of the code on whether this is correct or not.
rclpy/src/rclpy/names.cpp
Outdated
| // finalize the string map before returning | ||
| rcutils_ret = rcutils_string_map_fini(&substitutions_map); | ||
| if (rcutils_ret != RCUTILS_RET_OK) { | ||
| fprintf( |
There was a problem hiding this comment.
@sloretz FYI there's RCUTILS_SAFE_FWRITE_TO_STDERR too.
There was a problem hiding this comment.
Oops, I skimmed over the fact you are actually formatting. Either disregard or drop the integer formatting and use two safe writes.
There was a problem hiding this comment.
Uses two calls to RCUTILS_SAFE_FWRITE_TO_STDERR in 90f1052
rclpy/src/rclpy/names.cpp
Outdated
| throw RCLError("failed to get node options"); | ||
| } | ||
|
|
||
| char * output_cstr = NULL; |
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
hidmic
left a comment
There was a problem hiding this comment.
LGTM but for a few minor nits I won't block on.
rclpy/src/rclpy/names.cpp
Outdated
| auto resolved_name = std::unique_ptr<char, decltype(name_deleter)>( | ||
| output_cstr, name_deleter); | ||
|
|
||
| if (ret != RCL_RET_OK) { |
| node_options->allocator.deallocate(name, node_options->allocator.state); | ||
| }; | ||
| auto resolved_name = std::unique_ptr<char, decltype(name_deleter)>( | ||
| output_cstr, name_deleter); |
There was a problem hiding this comment.
@sloretz FYI, nit^N: RCPPUTILS_SCOPE_EXIT may be handy in these cases.
There was a problem hiding this comment.
Noted, I'll use this on the next PR once the rcpputils dependency is added.
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Part of #665
This uses pybind11 for name-related functions. I also added
RCUtilsErrorsince it was useful for one of the functions, and relaxed test expectations on theTypeErrorhuman readable text since the text output by pybind11 is a little bit different when an argument is the wrong type.