Skip to content

Commit 0823be2

Browse files
Add more logging info to storage and reader/writer open operations (#1881)
Signed-off-by: Michael Orlov <[email protected]>
1 parent aa71be7 commit 0823be2

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

rosbag2_cpp/src/rosbag2_cpp/readers/sequential_reader.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ void SequentialReader::open(
8787
const rosbag2_storage::StorageOptions & storage_options,
8888
const ConverterOptions & converter_options)
8989
{
90+
if (storage_options.uri.empty()) {
91+
throw std::runtime_error("Can't open rosbag2_cpp::SequentialReader. The input URI is empty");
92+
}
93+
9094
storage_options_ = storage_options;
9195
base_folder_ = storage_options.uri;
9296

@@ -108,7 +112,8 @@ void SequentialReader::open(
108112
} else {
109113
storage_ = storage_factory_->open_read_only(storage_options_);
110114
if (!storage_) {
111-
throw std::runtime_error{"No storage could be initialized from the inputs."};
115+
throw std::runtime_error("No storage could be initialized for the input URI: " +
116+
storage_options.uri);
112117
}
113118
if (!set_read_order(read_order_)) {
114119
ROSBAG2_CPP_LOG_WARN(

rosbag2_cpp/src/rosbag2_cpp/writers/sequential_writer.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ void SequentialWriter::open(
103103
if (is_open_) {
104104
return; // The writer already opened
105105
}
106+
if (storage_options.uri.empty()) {
107+
throw std::runtime_error("Can't open rosbag2_cpp::SequentialWriter. The input URI is empty");
108+
}
109+
106110
base_folder_ = storage_options.uri;
107111
storage_options_ = storage_options;
108112

rosbag2_cpp/test/rosbag2_cpp/test_storage_without_metadata_file.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ TEST_F(StorageWithoutMetadataFileTest, open_uses_storage_id_from_storage_options
7474
EXPECT_CALL(*metadata_io, metadata_file_exists).Times(1).WillOnce(Return(false));
7575

7676
rosbag2_storage::StorageOptions storage_options;
77+
storage_options.uri = "foo.bar";
7778
storage_options.storage_id = kStorageId;
7879

7980
auto sequential_reader = std::make_unique<rosbag2_cpp::readers::SequentialReader>(

rosbag2_storage/src/rosbag2_storage/impl/storage_factory_impl.hpp

+34-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <algorithm>
2020
#include <memory>
2121
#include <string>
22+
#include <unordered_set>
23+
#include <vector>
2224

2325
#include "pluginlib/class_loader.hpp"
2426

@@ -160,19 +162,38 @@ class StorageFactoryImpl
160162

161163
virtual ~StorageFactoryImpl() = default;
162164

165+
std::unordered_set<std::string> get_registered_plugin_names()
166+
{
167+
std::vector<std::string> read_only_plugins = read_only_class_loader_->getDeclaredClasses();
168+
std::vector<std::string> read_write_plugins = read_write_class_loader_->getDeclaredClasses();
169+
170+
// Merge read-only and read-write plugins
171+
std::unordered_set<std::string> combined_plugins(
172+
read_only_plugins.begin(), read_only_plugins.end());
173+
combined_plugins.insert(read_write_plugins.begin(), read_write_plugins.end());
174+
return combined_plugins;
175+
}
176+
163177
std::shared_ptr<ReadWriteInterface> open_read_write(const StorageOptions & storage_options)
164178
{
165-
auto instance =
166-
get_interface_instance(read_write_class_loader_, storage_options);
179+
auto instance = get_interface_instance(read_write_class_loader_, storage_options);
167180

168181
if (instance == nullptr) {
169182
if (storage_options.storage_id.empty()) {
170183
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
171-
"No storage id specified, and no plugin found that could open URI");
184+
"No storage id specified, and no plugin found that could open URI: '" <<
185+
storage_options.uri << "'");
172186
} else {
173187
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
174188
"Could not load/open plugin with storage id '" << storage_options.storage_id << "'");
175189
}
190+
auto available_plugins = read_write_class_loader_->getDeclaredClasses();
191+
std::stringstream ss;
192+
ss << "Available read-write storage plugins: ";
193+
for (const auto & storage_plugin : available_plugins) {
194+
ss << "'" << storage_plugin << "', ";
195+
}
196+
ROSBAG2_STORAGE_LOG_INFO("%s", ss.str().c_str());
176197
}
177198

178199
return instance;
@@ -193,11 +214,19 @@ class StorageFactoryImpl
193214
if (instance == nullptr) {
194215
if (storage_options.storage_id.empty()) {
195216
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
196-
"No storage id specified, and no plugin found that could open URI");
217+
"No storage id specified, and no plugin found that could open URI: '" <<
218+
storage_options.uri << "'");
197219
} else {
198220
ROSBAG2_STORAGE_LOG_ERROR_STREAM(
199-
"Could not load/open plugin with storage id '" << storage_options.storage_id << "'");
221+
"Could not load/open plugin with storage id: '" << storage_options.storage_id << "'");
222+
}
223+
auto available_plugins = get_registered_plugin_names();
224+
std::stringstream ss;
225+
ss << "Available storage plugins: ";
226+
for (const auto & storage_plugin : available_plugins) {
227+
ss << "'" << storage_plugin << "', ";
200228
}
229+
ROSBAG2_STORAGE_LOG_INFO("%s", ss.str().c_str());
201230
}
202231

203232
return instance;

0 commit comments

Comments
 (0)