Skip to content

Refactor repeated storage connection retrieval into helper function #158

@coderabbitai

Description

@coderabbitai

Problem

The code pattern for retrieving storage connections from m_storage_factory->provide_storage_connection() and handling errors is repeated in multiple places throughout the codebase. This leads to code duplication and makes maintenance more difficult.

Current Pattern

std::variant<std::unique_ptr<core::StorageConnection>, core::StorageErr> conn_result
        = m_storage_factory->provide_storage_connection();
if (std::holds_alternative<core::StorageErr>(conn_result)) {
    throw ConnectionException(std::get<core::StorageErr>(conn_result).description);
}
auto conn = std::move(std::get<std::unique_ptr<core::StorageConnection>>(conn_result));

Proposed Solution

Create a helper method that encapsulates this pattern, potentially something like:

auto try_storage_connection() -> std::unique_ptr<core::StorageConnection>;

This would simplify the calling code and centralize error handling for storage connection retrieval.

Context

This issue was identified during PR review.

References:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions