Skip to content

Commit b7278a9

Browse files
committed
Review update
1 parent 25a84f8 commit b7278a9

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

extensions/couchbase/controllerservices/CouchbaseClusterService.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ CouchbaseErrorType CouchbaseClient::getErrorType(const std::error_code& error_co
3535
}
3636

3737
nonstd::expected<::couchbase::collection, CouchbaseErrorType> CouchbaseClient::getCollection(const CouchbaseCollection& collection) {
38-
if (auto error_type = establishConnection()) {
39-
return nonstd::make_unexpected(*error_type);
38+
auto connection_result = establishConnection();
39+
if (!connection_result) {
40+
return nonstd::make_unexpected(connection_result.error());
4041
}
4142
return cluster_->bucket(collection.bucket_name).scope(collection.scope_name).collection(collection.collection_name);
4243
}
@@ -88,19 +89,19 @@ void CouchbaseClient::close() {
8889
}
8990
}
9091

91-
std::optional<CouchbaseErrorType> CouchbaseClient::establishConnection() {
92+
nonstd::expected<void, CouchbaseErrorType> CouchbaseClient::establishConnection() {
9293
if (cluster_) {
93-
return std::nullopt;
94+
return {};
9495
}
9596

9697
auto options = ::couchbase::cluster_options(username_, password_);
9798
auto [connect_err, cluster] = ::couchbase::cluster::connect(connection_string_, options).get();
9899
if (connect_err.ec()) {
99100
logger_->log_error("Failed to connect to Couchbase cluster with error code: '{}' and message: '{}'", connect_err.ec(), connect_err.message());
100-
return getErrorType(connect_err.ec());
101+
return nonstd::make_unexpected(getErrorType(connect_err.ec()));
101102
}
102103
cluster_ = std::move(cluster);
103-
return std::nullopt;
104+
return {};
104105
}
105106

106107
namespace controllers {
@@ -121,8 +122,9 @@ void CouchbaseClusterService::onEnable() {
121122
}
122123

123124
client_ = std::make_unique<CouchbaseClient>(connection_string, username, password, logger_);
124-
if (auto result = client_->establishConnection()) {
125-
if (result == CouchbaseErrorType::FATAL) {
125+
auto result = client_->establishConnection();
126+
if (!result) {
127+
if (result.error() == CouchbaseErrorType::FATAL) {
126128
throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Failed to connect to Couchbase cluster with fatal error");
127129
}
128130
logger_->log_warn("Failed to connect to Couchbase cluster with temporary error, will retry connection when a Couchbase processor is triggered");

extensions/couchbase/controllerservices/CouchbaseClusterService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CouchbaseClient {
6565

6666
nonstd::expected<CouchbaseUpsertResult, CouchbaseErrorType> upsert(const CouchbaseCollection& collection, CouchbaseValueType document_type, const std::string& document_id,
6767
const std::vector<std::byte>& buffer, const ::couchbase::upsert_options& options);
68-
std::optional<CouchbaseErrorType> establishConnection();
68+
nonstd::expected<void, CouchbaseErrorType> establishConnection();
6969
void close();
7070

7171
private:

0 commit comments

Comments
 (0)