From a2a2ffd8ea10a1b23ed3a1aea2c8c4912fb39420 Mon Sep 17 00:00:00 2001 From: avalen2022 Date: Thu, 23 Apr 2026 15:42:39 +0200 Subject: [PATCH] fix(ros2_parser): strip namespace suffix instead of a fixed 5 chars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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 `/action/_FeedbackMessage` the namespace is `::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) --- src/ros_parsers/ros2_parser.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ros_parsers/ros2_parser.cpp b/src/ros_parsers/ros2_parser.cpp index d6ee8be..b22f314 100644 --- a/src/ros_parsers/ros2_parser.cpp +++ b/src/ros_parsers/ros2_parser.cpp @@ -102,7 +102,15 @@ std::string CreateSchema(const std::string& base_type) case ROS_TYPE_MESSAGE: { auto type_info = reinterpret_cast(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)