Skip to content

Commit

Permalink
Allow unknown types in bag rewrite (#1812)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Orlov <[email protected]>
  • Loading branch information
MichaelOrlov authored Sep 23, 2024
1 parent fd8dd26 commit cd7bd63
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <utility>

#include <ament_index_cpp/get_package_share_directory.hpp>
#include <ament_index_cpp/get_package_prefix.hpp>

#include "rosbag2_cpp/logging.hpp"

Expand Down Expand Up @@ -179,7 +180,13 @@ const LocalMessageDefinitionSource::MessageSpec & LocalMessageDefinitionSource::
throw TypenameNotUnderstoodError(topic_type);
}
std::string package = match[1];
std::string share_dir = ament_index_cpp::get_package_share_directory(package);
std::string share_dir;
try {
share_dir = ament_index_cpp::get_package_share_directory(package);
} catch (const ament_index_cpp::PackageNotFoundError & e) {
ROSBAG2_CPP_LOG_WARN("'%s'", e.what());
throw DefinitionNotFoundError(definition_identifier.topic_type());
}
std::string dir = definition_identifier.format() == Format::MSG ||
definition_identifier.format() == Format::IDL ? "/msg/" : "/srv/";
std::ifstream file{share_dir + dir + match[2].str() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,18 @@ TEST(test_local_message_definition_source, no_crash_on_bad_name)
});
ASSERT_EQ(result.encoding, "unknown");
}

TEST(test_local_message_definition_source, throw_definition_not_found_for_unknown_msg)
{
LocalMessageDefinitionSource source;
ASSERT_THROW(
{
source.get_full_text("rosbag2_test_msgdefs/msg/UnknownMessage");
}, rosbag2_cpp::DefinitionNotFoundError);

// Throw DefinitionNotFoundError for not found message definition package name
ASSERT_THROW(
{
source.get_full_text("not_found_msgdefs_pkg/msg/UnknownMessage");
}, rosbag2_cpp::DefinitionNotFoundError);
}
2 changes: 1 addition & 1 deletion rosbag2_transport/src/rosbag2_transport/bag_rewrite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ setup_topic_filtering(
}

for (const auto & [writer, record_options] : output_bags) {
rosbag2_transport::TopicFilter topic_filter{record_options};
rosbag2_transport::TopicFilter topic_filter{record_options, nullptr, true};
auto filtered_topics_and_types = topic_filter.filter_topics(input_topics);

// Done filtering - set up writer
Expand Down

0 comments on commit cd7bd63

Please sign in to comment.