Skip to content

Commit 14660b4

Browse files
Fail PersistentSequence if input port is not set (#5589)
* Fail if getInput fails Signed-off-by: redvinaa <redvinaa@gmail.com> * Add test with no input Signed-off-by: redvinaa <redvinaa@gmail.com> * Update error string Co-authored-by: Steve Macenski <stevenmacenski@gmail.com> Signed-off-by: Vince Reda <60265874+redvinaa@users.noreply.github.com> * Fix quotation marks Signed-off-by: redvinaa <redvinaa@gmail.com> --------- Signed-off-by: redvinaa <redvinaa@gmail.com> Signed-off-by: Vince Reda <60265874+redvinaa@users.noreply.github.com> Co-authored-by: Steve Macenski <stevenmacenski@gmail.com>
1 parent 0c20df2 commit 14660b4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

nav2_behavior_tree/plugins/control/persistent_sequence.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ BT::NodeStatus PersistentSequenceNode::tick()
2929
const int children_count = children_nodes_.size();
3030

3131
int current_child_idx;
32-
getInput("current_child_idx", current_child_idx);
32+
if (!getInput("current_child_idx", current_child_idx)) {
33+
throw BT::RuntimeError(
34+
"Missing required input [current_child_idx] in PersistentSequenceNode. "
35+
"Set via <Script code=\"current_child_idx := 0\" />");
36+
}
3337

3438
setStatus(BT::NodeStatus::RUNNING);
3539

nav2_behavior_tree/test/plugins/control/test_persistent_sequence.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,23 @@ std::shared_ptr<BT::BehaviorTreeFactory>
6262
PersistentSequenceTestFixture::factory_ = nullptr;
6363
std::shared_ptr<BT::Tree> PersistentSequenceTestFixture::tree_ = nullptr;
6464

65+
TEST_F(PersistentSequenceTestFixture, test_empty_fails)
66+
{
67+
// create tree
68+
std::string xml_txt =
69+
R"(
70+
<root BTCPP_format="4">
71+
<BehaviorTree ID="MainTree">
72+
<PersistentSequence>
73+
<AlwaysSuccess/>
74+
</PersistentSequence>
75+
</BehaviorTree>
76+
</root>)";
77+
tree_ = std::make_shared<BT::Tree>(factory_->createTreeFromText(xml_txt, config_->blackboard));
78+
79+
EXPECT_THROW(tree_->rootNode()->executeTick(), BT::RuntimeError);
80+
}
81+
6582
TEST_F(PersistentSequenceTestFixture, test_tick)
6683
{
6784
// create tree

0 commit comments

Comments
 (0)