rosbag2
rosbag2 copied to clipboard
No error is reported when the RecordOptions YAML type is invalid
Description
During the YAML parsing of rosbag2_transport::RecordOptions, if a field exists but its type is incorrect, the parsing function does not detect the error and silently accepts the invalid configuration.
Expected Behavior
Parsing should fail and an exception should be thrown when a YAML field type does not match.
Actual Behavior
In YAML, a field has a type error, but no exception is thrown and it is parsed successfully.
To Reproduce
Test Case
#include <gmock/gmock.h>
#include <string>
#include "rosbag2_transport/record_options.hpp"
using namespace ::testing; // NOLINT
TEST(record_options, test)
{
std::string serialized_record_options =
" all_topics: invalid_bool\n"
" rmw_serialization_format: 42\n";
YAML::Node loaded_node = YAML::Load(serialized_record_options);
EXPECT_THROW(
loaded_node.as<rosbag2_transport::RecordOptions>(),
YAML::TypedBadConversion<rosbag2_transport::RecordOptions>);
}
Output
[ RUN ] record_options.test
/home/shangzh/rosbag2_ws/rosbag2/rosbag2_transport/test/rosbag2_transport/test_record_options.cpp:12: Failure
Expected: loaded_node.as<rosbag2_transport::RecordOptions>() throws an exception of type YAML::TypedBadConversion<rosbag2_transport::RecordOptions>.
Actual: it throws nothing.
[ FAILED ] record_options.test (1 ms)
[----------] 1 test from record_options (1 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (1 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] record_options.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