Skip to content

Commit 16af46c

Browse files
committed
better error messages
1 parent 3c4cc59 commit 16af46c

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

include/behaviortree_cpp/basic_types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,13 @@ using StringConvertersMap = std::unordered_map<const std::type_info*, StringConv
138138
template <typename T> [[nodiscard]]
139139
inline StringConverter GetAnyFromStringFunctor()
140140
{
141-
return [](StringView str) { return Any(convertFromString<T>(str)); };
141+
if constexpr(std::is_constructible_v<StringView, T>)
142+
{
143+
return [](StringView str) { return Any(str); };
144+
}
145+
else {
146+
return [](StringView str) { return Any(convertFromString<T>(str)); };
147+
}
142148
}
143149

144150
template <> [[nodiscard]]

include/behaviortree_cpp/blackboard.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ class Blackboard
149149
{
150150
// create a new entry
151151
Any new_value(value);
152-
PortInfo new_port(PortDirection::INOUT, new_value.type(), {});
152+
PortInfo new_port(PortDirection::INOUT, new_value.type(),
153+
GetAnyFromStringFunctor<T>());
153154
lock.unlock();
154155
auto entry = createEntryImpl(key, new_port);
155156
lock.lock();
@@ -199,10 +200,10 @@ class Blackboard
199200
{
200201
debugMessage();
201202

202-
throw LogicError("Blackboard::set() failed: once declared, the type of a port "
203-
"shall not change. Declared type [",
204-
BT::demangle(previous_type), "] != current type [",
205-
BT::demangle(typeid(T)), "]");
203+
auto msg = StrCat("Blackboard entry [", key, "]: once declared, the type of a port"
204+
" shall not change. Previously declared type [", BT::demangle(previous_type),
205+
"], current type [", BT::demangle(typeid(T)), "]");
206+
throw LogicError(msg);
206207
}
207208
}
208209
previous_any = std::move(new_value);

src/blackboard.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ Blackboard::createEntryImpl(const std::string& key, const PortInfo& info)
8181
old_type != typeid(BT::PortInfo::AnyTypeAllowed) &&
8282
info.type() != typeid(BT::PortInfo::AnyTypeAllowed))
8383
{
84-
throw LogicError("Blackboard: once declared, the type of a port "
85-
"shall not change. Previously declared type [",
86-
BT::demangle(old_type), "] != new type [",
87-
BT::demangle(info.type()), "]");
84+
auto msg = StrCat("Blackboard entry [", key, "]: once declared, the type of a port"
85+
" shall not change. Previously declared type [", BT::demangle(old_type),
86+
"], current type [", BT::demangle(typeid(info.type())), "]");
87+
88+
throw LogicError(msg);
8889
}
8990
return storage_it->second;
9091
}

tests/gtest_subtree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ TEST(SubTree, SubtreeIssue563)
351351
<BehaviorTree ID="Talker">
352352
<Sequence>
353353
<SaySomething message="{the_message}" />
354-
<SetBlackboard output_key="reply" value="done"/>
354+
<Script code=" reply:='done' "/>
355355
</Sequence>
356356
</BehaviorTree>
357357

0 commit comments

Comments
 (0)