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]>
(cherry picked from commit cd7bd63)

# Conflicts:
#	rosbag2_cpp/src/rosbag2_cpp/message_definitions/local_message_definition_source.cpp
  • Loading branch information
MichaelOrlov authored and mergify[bot] committed Sep 23, 2024
1 parent 64e7dec commit d3362a4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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 @@ -165,8 +166,21 @@ const LocalMessageDefinitionSource::MessageSpec & LocalMessageDefinitionSource::
throw TypenameNotUnderstoodError(topic_type);
}
std::string package = match[1];
<<<<<<< HEAD
std::string share_dir = ament_index_cpp::get_package_share_directory(package);
std::ifstream file{share_dir + "/msg/" + match[2].str() +
=======
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() +
>>>>>>> cd7bd636 (Allow unknown types in bag rewrite (#1812))
extension_for_format(definition_identifier.format())};
if (!file.good()) {
throw DefinitionNotFoundError(definition_identifier.topic_type());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,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 d3362a4

Please sign in to comment.