Skip to content

Commit

Permalink
Log missing pairs only once
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Clephas <[email protected]>
  • Loading branch information
Timple committed Mar 3, 2023
1 parent 3d5328d commit 95c3318
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/dynamic_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,17 @@ void update_bridge(
bridge.ros1_type_name, topic_name, 10,
bridge.ros2_type_name, topic_name, ros2_publisher_qos);
} catch (std::runtime_error & e) {
fprintf(
stderr,
"failed to create 1to2 bridge for topic '%s' "
"with ROS 1 type '%s' and ROS 2 type '%s': %s\n",
topic_name.c_str(), bridge.ros1_type_name.c_str(), bridge.ros2_type_name.c_str(), e.what());
if (std::string(e.what()).find("No template specialization") != std::string::npos) {
fprintf(stderr, "check the list of supported pairs with the `--print-pairs` option\n");
static std::set<std::string> logged_topic_errors;
auto entry = logged_topic_errors.emplace(topic_name);
if (entry.second) { // topic name was not already in the set, so log once
fprintf(
stderr,
"failed to create 1to2 bridge for topic '%s' "
"with ROS 1 type '%s' and ROS 2 type '%s': %s\n",
topic_name.c_str(), bridge.ros1_type_name.c_str(), bridge.ros2_type_name.c_str(), e.what());
if (std::string(e.what()).find("No template specialization") != std::string::npos) {
fprintf(stderr, "check the list of supported pairs with the `--print-pairs` option\n");
}
}
continue;
}
Expand Down Expand Up @@ -258,13 +262,17 @@ void update_bridge(
bridge.ros2_type_name, topic_name, 10,
bridge.ros1_type_name, topic_name, 10);
} catch (std::runtime_error & e) {
fprintf(
stderr,
"failed to create 2to1 bridge for topic '%s' "
"with ROS 2 type '%s' and ROS 1 type '%s': %s\n",
topic_name.c_str(), bridge.ros2_type_name.c_str(), bridge.ros1_type_name.c_str(), e.what());
if (std::string(e.what()).find("No template specialization") != std::string::npos) {
fprintf(stderr, "check the list of supported pairs with the `--print-pairs` option\n");
static std::set<std::string> logged_topic_errors;
auto entry = logged_topic_errors.emplace(topic_name);
if (entry.second) { // topic name was not already in the set, so log once
fprintf(
stderr,
"failed to create 2to1 bridge for topic '%s' "
"with ROS 2 type '%s' and ROS 1 type '%s': %s\n",
topic_name.c_str(), bridge.ros2_type_name.c_str(), bridge.ros1_type_name.c_str(), e.what());
if (std::string(e.what()).find("No template specialization") != std::string::npos) {
fprintf(stderr, "check the list of supported pairs with the `--print-pairs` option\n");
}
}
continue;
}
Expand Down

0 comments on commit 95c3318

Please sign in to comment.