Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't warn for unknown types if topics are not selected #1466

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions rosbag2_transport/src/rosbag2_transport/topic_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,6 @@ std::unordered_map<std::string, std::string> TopicFilter::filter_topics(
bool TopicFilter::take_topic(
const std::string & topic_name, const std::vector<std::string> & topic_types)
{
if (!has_single_type(topic_name, topic_types)) {
return false;
}

const std::string & topic_type = topic_types[0];
MichaelOrlov marked this conversation as resolved.
Show resolved Hide resolved
if (!allow_unknown_types_ && !type_is_known(topic_name, topic_type)) {
return false;
}

if (!record_options_.include_hidden_topics && topic_is_hidden(topic_name)) {
RCUTILS_LOG_WARN_ONCE_NAMED(
ROSBAG2_TRANSPORT_PACKAGE_NAME,
"Hidden topics are not recorded. Enable them with --include-hidden-topics");
return false;
}

if (!record_options_.include_unpublished_topics && node_graph_ &&
topic_is_unpublished(topic_name, *node_graph_))
{
Expand Down Expand Up @@ -163,6 +147,22 @@ bool TopicFilter::take_topic(
return false;
}

if (!has_single_type(topic_name, topic_types)) {
return false;
}

if (!record_options_.include_hidden_topics && topic_is_hidden(topic_name)) {
RCUTILS_LOG_WARN_ONCE_NAMED(
ROSBAG2_TRANSPORT_PACKAGE_NAME,
"Hidden topics are not recorded. Enable them with --include-hidden-topics");
return false;
}

const std::string & topic_type = topic_types[0];
if (!allow_unknown_types_ && !type_is_known(topic_name, topic_type)) {
return false;
}

return true;
}

Expand Down
38 changes: 38 additions & 0 deletions rosbag2_transport/test/rosbag2_transport/test_topic_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,41 @@ TEST_F(RegexFixture, regex_all_and_filter)
auto filtered_topics = filter.filter_topics(topics_and_types_);
EXPECT_THAT(filtered_topics, SizeIs(6));
}

TEST_F(RegexFixture, do_not_print_warning_about_unknown_types_if_topic_is_not_selected) {
{ // Check for topics explicitly selected via "topics" list
rosbag2_transport::RecordOptions record_options;
// Select only one topic with name "/planning" via topic list
record_options.topics = {"/planning"};
record_options.all = false;
rosbag2_transport::TopicFilter filter{record_options, nullptr, false};
testing::internal::CaptureStderr();
auto filtered_topics = filter.filter_topics(topics_and_types_);
std::string test_output = testing::internal::GetCapturedStderr();
ASSERT_EQ(0u, filtered_topics.size());
EXPECT_TRUE(
test_output.find(
"Topic '/invalid_topic' has unknown type 'invalid_topic_type'") == std::string::npos);
EXPECT_TRUE(
test_output.find(
"Topic '/planning' has unknown type 'planning_topic_type'") != std::string::npos);
}

{ // Check for topics selected via regex
rosbag2_transport::RecordOptions record_options;
// Select only one topic with name "/planning" via regex
record_options.regex = "^/planning";
record_options.all = false;
rosbag2_transport::TopicFilter filter{record_options, nullptr, false};
testing::internal::CaptureStderr();
auto filtered_topics = filter.filter_topics(topics_and_types_);
std::string test_output = testing::internal::GetCapturedStderr();
ASSERT_EQ(0u, filtered_topics.size());
EXPECT_TRUE(
test_output.find(
"Topic '/invalid_topic' has unknown type 'invalid_topic_type'") == std::string::npos);
EXPECT_TRUE(
test_output.find(
"Topic '/planning' has unknown type 'planning_topic_type'") != std::string::npos);
}
}