Skip to content

Commit a395820

Browse files
authored
Fix case where list of composable nodes is zero (#173) (#209)
Otherwise, launch crashes due to an index-out-of-bounds exception. Signed-off-by: Jacob Perron <[email protected]>
1 parent 10241c1 commit a395820

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

launch_ros/launch_ros/actions/composable_node_container.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ def execute(self, context: LaunchContext) -> Optional[List[Action]]:
9494
composable nodes load action if it applies.
9595
"""
9696
load_actions = None # type: Optional[List[Action]]
97-
if self.__composable_node_descriptions is not None:
97+
if (
98+
self.__composable_node_descriptions is not None and
99+
len(self.__composable_node_descriptions) > 0
100+
):
98101
from .load_composable_nodes import LoadComposableNodes
99102
# Perform load action once the container has started.
100103
load_actions = [

test_launch_ros/test/test_launch_ros/actions/test_composable_node_container.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ def test_composable_node_container():
7272
assert get_node_name_count(context, f'/{TEST_NODE_NAMESPACE}/{TEST_NODE_NAME}') == 1
7373

7474

75+
def test_composable_node_container_empty_list_of_nodes():
76+
"""Test launching a ComposableNodeContainer with an empty list of nodes."""
77+
actions = [
78+
ComposableNodeContainer(
79+
package='rclcpp_components',
80+
executable='component_container',
81+
name=TEST_CONTAINER_NAME,
82+
namespace=TEST_CONTAINER_NAMESPACE,
83+
composable_node_descriptions=[]
84+
),
85+
]
86+
87+
context = _assert_launch_no_errors(actions)
88+
assert get_node_name_count(context, f'/{TEST_CONTAINER_NAMESPACE}/{TEST_CONTAINER_NAME}') == 1
89+
assert get_node_name_count(context, f'/{TEST_NODE_NAMESPACE}/{TEST_NODE_NAME}') == 0
90+
91+
7592
def test_composable_node_container_in_group_with_launch_configuration_in_description():
7693
"""
7794
Test launch configuration is passed to ComposableNode description inside GroupAction.

0 commit comments

Comments
 (0)