From b7278a98b1b16ece4ee042d4ddeecae40ff3bd9e Mon Sep 17 00:00:00 2001 From: Gabor Gyimesi Date: Mon, 14 Oct 2024 20:42:47 +0200 Subject: [PATCH] Review update --- .../CouchbaseClusterService.cpp | 18 ++++++++++-------- .../CouchbaseClusterService.h | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/extensions/couchbase/controllerservices/CouchbaseClusterService.cpp b/extensions/couchbase/controllerservices/CouchbaseClusterService.cpp index d40ada0728..8abf7985c1 100644 --- a/extensions/couchbase/controllerservices/CouchbaseClusterService.cpp +++ b/extensions/couchbase/controllerservices/CouchbaseClusterService.cpp @@ -35,8 +35,9 @@ CouchbaseErrorType CouchbaseClient::getErrorType(const std::error_code& error_co } nonstd::expected<::couchbase::collection, CouchbaseErrorType> CouchbaseClient::getCollection(const CouchbaseCollection& collection) { - if (auto error_type = establishConnection()) { - return nonstd::make_unexpected(*error_type); + auto connection_result = establishConnection(); + if (!connection_result) { + return nonstd::make_unexpected(connection_result.error()); } return cluster_->bucket(collection.bucket_name).scope(collection.scope_name).collection(collection.collection_name); } @@ -88,19 +89,19 @@ void CouchbaseClient::close() { } } -std::optional CouchbaseClient::establishConnection() { +nonstd::expected CouchbaseClient::establishConnection() { if (cluster_) { - return std::nullopt; + return {}; } auto options = ::couchbase::cluster_options(username_, password_); auto [connect_err, cluster] = ::couchbase::cluster::connect(connection_string_, options).get(); if (connect_err.ec()) { logger_->log_error("Failed to connect to Couchbase cluster with error code: '{}' and message: '{}'", connect_err.ec(), connect_err.message()); - return getErrorType(connect_err.ec()); + return nonstd::make_unexpected(getErrorType(connect_err.ec())); } cluster_ = std::move(cluster); - return std::nullopt; + return {}; } namespace controllers { @@ -121,8 +122,9 @@ void CouchbaseClusterService::onEnable() { } client_ = std::make_unique(connection_string, username, password, logger_); - if (auto result = client_->establishConnection()) { - if (result == CouchbaseErrorType::FATAL) { + auto result = client_->establishConnection(); + if (!result) { + if (result.error() == CouchbaseErrorType::FATAL) { throw minifi::Exception(ExceptionType::PROCESS_SCHEDULE_EXCEPTION, "Failed to connect to Couchbase cluster with fatal error"); } logger_->log_warn("Failed to connect to Couchbase cluster with temporary error, will retry connection when a Couchbase processor is triggered"); diff --git a/extensions/couchbase/controllerservices/CouchbaseClusterService.h b/extensions/couchbase/controllerservices/CouchbaseClusterService.h index 0d46975b03..0103404c2f 100644 --- a/extensions/couchbase/controllerservices/CouchbaseClusterService.h +++ b/extensions/couchbase/controllerservices/CouchbaseClusterService.h @@ -65,7 +65,7 @@ class CouchbaseClient { nonstd::expected upsert(const CouchbaseCollection& collection, CouchbaseValueType document_type, const std::string& document_id, const std::vector& buffer, const ::couchbase::upsert_options& options); - std::optional establishConnection(); + nonstd::expected establishConnection(); void close(); private: