Skip to content

The YAML parser of StorageOptions does not throw an exception for invalid input #2256

@zhihaoshang

Description

@zhihaoshang

Description

When parsing YAML nodes using YAML::convert::decode(), if the input contains clearly invalid field values, no exceptions are raised, causing invalid configurations to be silently accepted.

Expected Behavior

Throw an exception

Actual Behavior

No exception thrown

To Reproduce

Test Case

#include <gmock/gmock.h>
#include "rosbag2_storage/storage_options.hpp"
using namespace ::testing;  // NOLINT

TEST(storage_options, test)
{
  YAML::Node node;
  node["uri"] = "invalid_uri";
  node["storage_id"] = "";
  node["max_bagfile_size"] = "non_numeric_value";
  EXPECT_THROW(
    node.as<rosbag2_storage::StorageOptions>(),
    std::runtime_error);
}

Output

[ RUN      ] storage_options.test
/home/shangzh/rosbag2_ws/rosbag2/rosbag2_storage/test/rosbag2_storage/test_storage_options.cpp:11: Failure
Expected: node.as<rosbag2_storage::StorageOptions>() throws an exception of type std::runtime_error.
  Actual: it throws nothing.

[  FAILED  ] storage_options.test (0 ms)
[----------] 1 test from storage_options (0 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  ] storage_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions