From d3cfbd7612b5d2707b16da1b900dc772dd88a61c Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Fri, 9 Feb 2024 00:11:34 -0800 Subject: [PATCH] ros2 param dump should handle empty list as exception. (#881) * ros2 param dump should handle empty list as exception. Signed-off-by: Tomoya Fujita * avoid generating exception, instead printing the error messages. Signed-off-by: Tomoya Fujita --------- Signed-off-by: Tomoya Fujita --- ros2param/ros2param/verb/dump.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ros2param/ros2param/verb/dump.py b/ros2param/ros2param/verb/dump.py index be9cd71b1..d5c3de737 100644 --- a/ros2param/ros2param/verb/dump.py +++ b/ros2param/ros2param/verb/dump.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import sys + from rclpy.parameter import PARAMETER_SEPARATOR_STRING from ros2cli.node.direct import DirectNode from ros2cli.node.strategy import add_arguments @@ -52,7 +54,7 @@ def get_parameter_values(node, node_name, params): # requested parameter not set if not response.values: - return '# Parameter not set' + return None # extract type specific value return [get_value(parameter_value=i) for i in response.values] @@ -81,18 +83,25 @@ def main(self, *, args): # noqa: D102 # retrieve values response = call_list_parameters(node=node, node_name=absolute_node_name) if response is None: - raise RuntimeError( + print( 'Wait for service timed out waiting for ' - f'parameter services for node {node_name.full_name}') + f'parameter services for node {node_name.full_name}', file=sys.stderr) + return elif response.result() is None: e = response.exception() - raise RuntimeError( - 'Exception while calling service of node ' - f"'{node_name.full_name}': {e}") + print( + 'Exception while calling list_parameters service of node ' + f"'{node_name.full_name}': {e}", file=sys.stderr) + return response = response.result().result.names response = sorted(response) parameter_values = self.get_parameter_values(node, absolute_node_name, response) + if parameter_values is None: + print( + 'Exception while calling get_parameters service of node ' + f"'{node_name.full_name}': {e}", file=sys.stderr) + return for param_name, pval in zip(response, parameter_values): self.insert_dict(