Skip to content

Commit d3cfbd7

Browse files
authored
ros2 param dump should handle empty list as exception. (#881)
* 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]>
1 parent 27449f7 commit d3cfbd7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

ros2param/ros2param/verb/dump.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import sys
16+
1517
from rclpy.parameter import PARAMETER_SEPARATOR_STRING
1618
from ros2cli.node.direct import DirectNode
1719
from ros2cli.node.strategy import add_arguments
@@ -52,7 +54,7 @@ def get_parameter_values(node, node_name, params):
5254

5355
# requested parameter not set
5456
if not response.values:
55-
return '# Parameter not set'
57+
return None
5658

5759
# extract type specific value
5860
return [get_value(parameter_value=i) for i in response.values]
@@ -81,18 +83,25 @@ def main(self, *, args): # noqa: D102
8183
# retrieve values
8284
response = call_list_parameters(node=node, node_name=absolute_node_name)
8385
if response is None:
84-
raise RuntimeError(
86+
print(
8587
'Wait for service timed out waiting for '
86-
f'parameter services for node {node_name.full_name}')
88+
f'parameter services for node {node_name.full_name}', file=sys.stderr)
89+
return
8790
elif response.result() is None:
8891
e = response.exception()
89-
raise RuntimeError(
90-
'Exception while calling service of node '
91-
f"'{node_name.full_name}': {e}")
92+
print(
93+
'Exception while calling list_parameters service of node '
94+
f"'{node_name.full_name}': {e}", file=sys.stderr)
95+
return
9296

9397
response = response.result().result.names
9498
response = sorted(response)
9599
parameter_values = self.get_parameter_values(node, absolute_node_name, response)
100+
if parameter_values is None:
101+
print(
102+
'Exception while calling get_parameters service of node '
103+
f"'{node_name.full_name}': {e}", file=sys.stderr)
104+
return
96105

97106
for param_name, pval in zip(response, parameter_values):
98107
self.insert_dict(

0 commit comments

Comments
 (0)