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

[jazzy] Add more logging info to storage and reader/writer open operations (backport #1881) #1882

Open
wants to merge 1 commit into
base: jazzy
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ void SequentialReader::open(
const rosbag2_storage::StorageOptions & storage_options,
const ConverterOptions & converter_options)
{
if (storage_options.uri.empty()) {
throw std::runtime_error("Can't open rosbag2_cpp::SequentialReader. The input URI is empty");
}

storage_options_ = storage_options;
base_folder_ = storage_options.uri;

Expand All @@ -108,7 +112,8 @@ void SequentialReader::open(
} else {
storage_ = storage_factory_->open_read_only(storage_options_);
if (!storage_) {
throw std::runtime_error{"No storage could be initialized from the inputs."};
throw std::runtime_error("No storage could be initialized for the input URI: " +
storage_options.uri);
}
if (!set_read_order(read_order_)) {
ROSBAG2_CPP_LOG_WARN(
Expand Down
4 changes: 4 additions & 0 deletions rosbag2_cpp/src/rosbag2_cpp/writers/sequential_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ void SequentialWriter::open(
if (is_open_) {
return; // The writer already opened
}
if (storage_options.uri.empty()) {
throw std::runtime_error("Can't open rosbag2_cpp::SequentialWriter. The input URI is empty");
}

base_folder_ = storage_options.uri;
storage_options_ = storage_options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ TEST_F(StorageWithoutMetadataFileTest, open_uses_storage_id_from_storage_options
EXPECT_CALL(*metadata_io, metadata_file_exists).Times(1).WillOnce(Return(false));

rosbag2_storage::StorageOptions storage_options;
storage_options.uri = "foo.bar";
storage_options.storage_id = kStorageId;

auto sequential_reader = std::make_unique<rosbag2_cpp::readers::SequentialReader>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <algorithm>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>

#include "pluginlib/class_loader.hpp"

Expand Down Expand Up @@ -160,19 +162,38 @@ class StorageFactoryImpl

virtual ~StorageFactoryImpl() = default;

std::unordered_set<std::string> get_registered_plugin_names()
{
std::vector<std::string> read_only_plugins = read_only_class_loader_->getDeclaredClasses();
std::vector<std::string> read_write_plugins = read_write_class_loader_->getDeclaredClasses();

// Merge read-only and read-write plugins
std::unordered_set<std::string> combined_plugins(
read_only_plugins.begin(), read_only_plugins.end());
combined_plugins.insert(read_write_plugins.begin(), read_write_plugins.end());
return combined_plugins;
}

std::shared_ptr<ReadWriteInterface> open_read_write(const StorageOptions & storage_options)
{
auto instance =
get_interface_instance(read_write_class_loader_, storage_options);
auto instance = get_interface_instance(read_write_class_loader_, storage_options);

if (instance == nullptr) {
if (storage_options.storage_id.empty()) {
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
"No storage id specified, and no plugin found that could open URI");
"No storage id specified, and no plugin found that could open URI: '" <<
storage_options.uri << "'");
} else {
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
"Could not load/open plugin with storage id '" << storage_options.storage_id << "'");
}
auto available_plugins = read_write_class_loader_->getDeclaredClasses();
std::stringstream ss;
ss << "Available read-write storage plugins: ";
for (const auto & storage_plugin : available_plugins) {
ss << "'" << storage_plugin << "', ";
}
ROSBAG2_STORAGE_LOG_INFO("%s", ss.str().c_str());
}

return instance;
Expand All @@ -193,11 +214,19 @@ class StorageFactoryImpl
if (instance == nullptr) {
if (storage_options.storage_id.empty()) {
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
"No storage id specified, and no plugin found that could open URI");
"No storage id specified, and no plugin found that could open URI: '" <<
storage_options.uri << "'");
} else {
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
"Could not load/open plugin with storage id '" << storage_options.storage_id << "'");
"Could not load/open plugin with storage id: '" << storage_options.storage_id << "'");
}
auto available_plugins = get_registered_plugin_names();
std::stringstream ss;
ss << "Available storage plugins: ";
for (const auto & storage_plugin : available_plugins) {
ss << "'" << storage_plugin << "', ";
}
ROSBAG2_STORAGE_LOG_INFO("%s", ss.str().c_str());
}

return instance;
Expand Down
Loading