rosbag2 icon indicating copy to clipboard operation
rosbag2 copied to clipboard

There is an asymmetry issue with RecordOptions YAML serialization, causing text round-trip deserialization to fail.

Open zhihaoshang opened this issue 1 week ago • 1 comments

Description

When performing YAML serialization and deserialization of rosbag2_transport::RecordOptions, the YAML content generated using YAML::convert<RecordOptions>::encode() will throw an exception after a round-trip in text form.

Expected Behavior

Should not raise an exception

Actual Behavior

Throw an exception

To Reproduce

Test Case

#include <gmock/gmock.h>
#include <string>
#include "rosbag2_transport/record_options.hpp"
using namespace ::testing;  // NOLINT

TEST(RecordOptionsTest, test) 
{
  rosbag2_transport::RecordOptions options;
  options.topics.reserve(2);
  options.topics.push_back("topic");
  options.topics.push_back("other_topic");
  options.exclude_topics.reserve(2);
  options.exclude_topics.push_back("exclude_topic1");
  options.exclude_topics.push_back("exclude_topic2");
  
  YAML::Node node = YAML::convert<rosbag2_transport::RecordOptions>().encode(options);
  std::stringstream ss;
  ss << node;
  YAML::Node reconstructed_node = YAML::Load(ss.str());
  rosbag2_transport::RecordOptions reconstructed = reconstructed_node.as<rosbag2_transport::RecordOptions>();

  for (size_t i = 0; i < options.topics.size(); ++i) {
    EXPECT_EQ(options.topics[i], reconstructed.topics[i]);
  }

  for (size_t i = 0; i < options.exclude_topics.size(); ++i) {
    EXPECT_EQ(options.exclude_topics[i], reconstructed.exclude_topics[i]);
  }
}

Output

[ RUN      ] RecordOptionsTest.test
unknown file: Failure
C++ exception with description "yaml-cpp: error at line 30, column 3: bad conversion" thrown in the test body.

[  FAILED  ] RecordOptionsTest.test (5 ms)
[----------] 1 test from RecordOptionsTest (5 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (5 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] RecordOptionsTest.test

 1 FAILED TEST

System (please complete the following information)

OS: ubuntu 24.04 ROS 2 Distro: ros 2 jazzy Install Method: source Version: ros 2 jazzy build options: --mixin asan-gcc

zhihaoshang avatar Dec 19 '25 06:12 zhihaoshang