Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(ros2_parser): strip namespace suffix instead of a fixed 5 chars
`CreateSchema()` used a hard-coded `substr(0, size - 5)` to strip
"::msg" from a message's C++ namespace to recover the package name.
That works for normal messages (`sensor_msgs::msg`) and happens to
work for services (`::srv` is also 5 chars), but it silently mangles
action-generated messages whose namespace ends in `::action` (8 chars).

For a topic like `<pkg>/action/<Action>_FeedbackMessage` the namespace
is `<pkg>::action`. Stripping exactly 5 chars from e.g.
`docking::action` (15 chars) leaves `docking::a` — exactly the
truncated package name reported in #1060. Downstream lookups then
fail with "package not found".

Replace the hard-coded strip with a suffix check over the three known
generator namespaces (`::msg`, `::srv`, `::action`). Each is stripped
by its actual length, so action feedback topics subscribe cleanly and
services stay unchanged.

Closes #1060.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
  • Loading branch information
avalen2022 and claude committed Apr 24, 2026
commit a2a2ffd8ea10a1b23ed3a1aea2c8c4912fb39420
10 changes: 9 additions & 1 deletion src/ros_parsers/ros2_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,15 @@ std::string CreateSchema(const std::string& base_type)
case ROS_TYPE_MESSAGE: {
auto type_info = reinterpret_cast<const MessageMembers*>(member.members_->data);
std::string package = type_info->message_namespace_;
package = package.substr(0, package.size() - 5); // remove "::msg"
for (const std::string& suffix : { "::msg", "::srv", "::action" })
{
if (package.size() >= suffix.size() &&
package.compare(package.size() - suffix.size(), suffix.size(), suffix) == 0)
{
package.resize(package.size() - suffix.size());
break;
}
}
const std::string field_type = fmt::format("{}/{}", package, type_info->message_name_);
schema += field_type;
if (secondary_types_done.count(field_type) == 0)
Expand Down
Loading