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

[humble] Allow unknown types in bag rewrite (backport #1812) #1819

Merged
merged 3 commits into from
Sep 24, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading