Skip to content

Commit

Permalink
[humble] Allow unknown types in bag rewrite (backport #1812) (#1819)
Browse files Browse the repository at this point in the history
* Allow unknown types in bag rewrite (#1812)

Signed-off-by: Michael Orlov <[email protected]>
(cherry picked from commit cd7bd63)
  • Loading branch information
mergify[bot] authored Sep 24, 2024
1 parent 25ecab6 commit f997e40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion rosbag2_storage_mcap/src/message_definition_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "rosbag2_storage_mcap/message_definition_cache.hpp"

#include <ament_index_cpp/get_package_prefix.hpp>
#include <ament_index_cpp/get_package_share_directory.hpp>
#include <ament_index_cpp/get_resource.hpp>
#include <ament_index_cpp/get_resources.hpp>
Expand Down Expand Up @@ -165,7 +166,13 @@ const MessageSpec & MessageDefinitionCache::load_message_spec(
namespace_name = "msg";
}
const std::string type_name = match[3];
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) {
RCUTILS_LOG_WARN_NAMED("rosbag2_storage_mcap", "%s", e.what());
throw DefinitionNotFoundError(definition_identifier.package_resource_name);
}
std::ifstream file{share_dir + "/" + namespace_name + "/" + type_name +
extension_for_format(definition_identifier.format)};
if (!file.good()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ TEST(test_message_definition_cache, get_service_message_definitions)
ASSERT_EQ(result.first, rosbag2_storage_mcap::internal::Format::MSG);
ASSERT_EQ(result.second, "\nstring resp\n");
}

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

// Throw DefinitionNotFoundError for not found message definition package name
ASSERT_THROW({ source.get_full_text("not_found_msgdefs_pkg/msg/UnknownMessage"); },
rosbag2_storage_mcap::internal::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 @@ -103,7 +103,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 f997e40

Please sign in to comment.