Skip to content

Commit 688905d

Browse files
committed
Throw Result instead
1 parent ba714ea commit 688905d

3 files changed

Lines changed: 6 additions & 19 deletions

File tree

lib/ClientConnection.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
189189
LOG_INFO(cnxString_ << "Create ClientConnection, timeout=" << clientConfiguration.getConnectionTimeout());
190190
if (!authentication_) {
191191
LOG_ERROR("Invalid authentication plugin");
192-
throw ResultException{ResultAuthenticationError};
192+
throw ResultAuthenticationError;
193193
}
194194
if (clientConfiguration.isUseTls()) {
195195
#if BOOST_VERSION >= 105400
@@ -211,7 +211,7 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
211211
ctx.load_verify_file(trustCertFilePath);
212212
} else {
213213
LOG_ERROR(trustCertFilePath << ": No such trustCertFile");
214-
throw ResultException{ResultAuthenticationError};
214+
throw ResultAuthenticationError;
215215
}
216216
} else {
217217
ctx.set_default_verify_paths();
@@ -228,11 +228,11 @@ ClientConnection::ClientConnection(const std::string& logicalAddress, const std:
228228
tlsPrivateKey = authData->getTlsPrivateKey();
229229
if (!file_exists(tlsCertificates)) {
230230
LOG_ERROR(tlsCertificates << ": No such tlsCertificates");
231-
throw ResultException{ResultAuthenticationError};
231+
throw ResultAuthenticationError;
232232
}
233233
if (!file_exists(tlsCertificates)) {
234234
LOG_ERROR(tlsCertificates << ": No such tlsCertificates");
235-
throw ResultException{ResultAuthenticationError};
235+
throw ResultAuthenticationError;
236236
}
237237
ctx.use_private_key_file(tlsPrivateKey, boost::asio::ssl::context::pem);
238238
ctx.use_certificate_file(tlsCertificates, boost::asio::ssl::context::pem);

lib/ConnectionPool.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "ClientConnection.h"
2525
#include "ExecutorService.h"
2626
#include "LogUtils.h"
27-
#include "ResultUtils.h"
2827

2928
using boost::asio::ip::tcp;
3029
namespace ssl = boost::asio::ssl;
@@ -96,8 +95,8 @@ auto ConnectionPool::getConnectionAsync(const std::string& logicalAddress, const
9695
cnx.reset(new ClientConnection(logicalAddress, physicalAddress, executorProvider_->get(keySuffix),
9796
clientConfiguration_, authentication_, clientVersion_, *this,
9897
keySuffix));
99-
} catch (const ResultException& e) {
100-
return ConnectionFuture::failure(e.result());
98+
} catch (Result result) {
99+
return ConnectionFuture::failure(result);
101100
} catch (const std::runtime_error& e) {
102101
lock.unlock();
103102
LOG_ERROR("Failed to create connection: " << e.what())

lib/ResultUtils.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,10 @@
2020

2121
#include <pulsar/Result.h>
2222

23-
#include <exception>
24-
2523
namespace pulsar {
2624

2725
inline bool isResultRetryable(Result result) {
2826
return result == ResultRetryable || result == ResultDisconnected;
2927
}
3028

31-
class ResultException : public std::exception {
32-
public:
33-
ResultException(Result result) : result_(result) {}
34-
Result result() const noexcept { return result_; }
35-
const char* what() const noexcept { return strResult(result_); }
36-
37-
private:
38-
const Result result_;
39-
};
40-
4129
} // namespace pulsar

0 commit comments

Comments
 (0)