Skip to content

Commit

Permalink
ros2 param dump should handle empty list as exception. (#881)
Browse files Browse the repository at this point in the history
* ros2 param dump should handle empty list as exception.

Signed-off-by: Tomoya Fujita <[email protected]>

* avoid generating exception, instead printing the error messages.

Signed-off-by: Tomoya Fujita <[email protected]>

---------

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya authored Feb 9, 2024
1 parent 27449f7 commit d3cfbd7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ros2param/ros2param/verb/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d3cfbd7

Please sign in to comment.