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

fix ipc_endpoint::setup() returns error when database_name is empty #146

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
17 changes: 11 additions & 6 deletions src/tateyama/endpoint/ipc/bootstrap/ipc_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ class ipc_endpoint : public endpoint {
* @brief setup the component (the state will be `ready`)
*/
bool setup(environment& env) override {
// create listener object
listener_ = std::make_unique<tateyama::server::ipc_listener>(
env.configuration(),
env.service_repository().find<framework::routing_service>(),
env.resource_repository().find<status_info::resource::bridge>()
);
try {
// create listener object
listener_ = std::make_unique<tateyama::server::ipc_listener>(
env.configuration(),
env.service_repository().find<framework::routing_service>(),
env.resource_repository().find<status_info::resource::bridge>()
);
} catch (std::runtime_error &ex) {
LOG_LP(ERROR) << ex.what();
return false;
}
return true;
}

Expand Down
18 changes: 8 additions & 10 deletions src/tateyama/endpoint/ipc/bootstrap/ipc_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,34 @@ class ipc_listener {
{
auto endpoint_config = cfg->get_section("ipc_endpoint");
if (endpoint_config == nullptr) {
LOG_LP(ERROR) << "cannot find ipc_endpoint section in the configuration";
exit(1);
throw std::runtime_error("cannot find ipc_endpoint section in the configuration");
}

auto database_name_opt = endpoint_config->get<std::string>("database_name");
if (!database_name_opt) {
LOG_LP(ERROR) << "cannot find database_name at the section in the configuration";
exit(1);
throw std::runtime_error("cannot find database_name at the section in the configuration");
}
database_name_ = database_name_opt.value();
if (database_name_.empty()) {
throw std::runtime_error("database_name in ipc_endpoint section should not be empty");
}

auto threads_opt = endpoint_config->get<std::size_t>("threads");
if (!threads_opt) {
LOG_LP(ERROR) << "cannot find thread_pool_size at the section in the configuration";
exit(1);
throw std::runtime_error("cannot find thread_pool_size at the section in the configuration");
}
auto threads = threads_opt.value();

auto datachannel_buffer_size_opt = endpoint_config->get<std::size_t>("datachannel_buffer_size");
if (!datachannel_buffer_size_opt) {
LOG_LP(ERROR) << "cannot find datachannel_buffer_size at the section in the configuration";
exit(1);
throw std::runtime_error("cannot find datachannel_buffer_size at the section in the configuration");
}
datachannel_buffer_size_ = datachannel_buffer_size_opt.value() * 1024; // in KB
VLOG_LP(log_debug) << "datachannel_buffer_size = " << datachannel_buffer_size_ << " bytes";

auto max_datachannel_buffers_opt = endpoint_config->get<std::size_t>("max_datachannel_buffers");
if (!max_datachannel_buffers_opt) {
LOG_LP(ERROR) << "cannot find max_datachannel_buffers at the section in the configuration";
exit(1);
throw std::runtime_error("cannot find max_datachannel_buffers at the section in the configuration");
}
max_datachannel_buffers_ = max_datachannel_buffers_opt.value();
VLOG_LP(log_debug) << "max_datachannel_buffers = " << max_datachannel_buffers_;
Expand Down