Skip to content
Snippets Groups Projects

Better Error Handling and Logging

Merged Timm Fitschen requested to merge dev into main
All threads resolved!
7 files
+ 263
57
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 48
13
@@ -45,6 +45,7 @@ using caosdb::entity::v1alpha1::EntityTransactionService;
using caosdb::info::VersionInfo;
using caosdb::info::v1alpha1::GeneralInfoService;
using caosdb::transaction::Transaction;
using caosdb::transaction::TransactionStatus;
using grpc::ChannelCredentials;
class CertificateProvider {
@@ -82,11 +83,7 @@ private:
public:
ConnectionConfiguration(const std::string &host, int port);
virtual ~ConnectionConfiguration() = default;
friend auto operator<<(std::ostream &out,
const ConnectionConfiguration &configuration)
-> std::ostream &;
[[nodiscard]] auto virtual ToString() const -> std::string = 0;
[[nodiscard]] auto GetHost() const -> std::string;
[[nodiscard]] auto GetPort() const -> int;
[[nodiscard]] auto virtual GetChannelCredentials() const
@@ -101,7 +98,6 @@ public:
InsecureConnectionConfiguration(const std::string &host, int port);
[[nodiscard]] auto GetChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> override;
[[nodiscard]] auto ToString() const -> std::string override;
};
class TlsConnectionConfiguration : public ConnectionConfiguration {
@@ -120,23 +116,62 @@ public:
const Authenticator &authenticator);
[[nodiscard]] auto GetChannelCredentials() const
-> std::shared_ptr<ChannelCredentials> override;
[[nodiscard]] auto ToString() const -> std::string override;
};
/**
* @brief A reusable connection to a CaosDBServer.
*/
class Connection {
std::shared_ptr<grpc::Channel> channel;
std::unique_ptr<GeneralInfoService::Stub> general_info_service;
std::shared_ptr<EntityTransactionService::Stub> entity_transaction_service;
public:
explicit Connection(const ConnectionConfiguration &configuration);
friend auto operator<<(std::ostream &out, const Connection &connection)
-> std::ostream &;
[[nodiscard]] auto GetVersionInfo() const -> std::unique_ptr<VersionInfo>;
/**
* Request the server's version and return the status of this request after
* termination..
*
* The version is stored in the connection object and may be retrieved via
* GetVersionInfo() if the request was successful.
*
* This method does not throw any exceptions. Errors are indicated in the
* return value instead.
*/
auto RetrieveVersionInfoNoExceptions() const noexcept -> TransactionStatus;
/**
* Request and return the server's version.
*
* If the request terminated unsuccessfully, a corresponding exception is
* being thrown.
*/
auto RetrieveVersionInfo() const -> const VersionInfo &;
/**
* Return the server's version.
*
* Clients need to call RetrieveVersionInfo() or
* RetrieveVersionInfoNoExceptions() before the version info is locally
* available. Otherwise an empty instance is being returned.
*/
[[nodiscard]] inline auto GetVersionInfo() const noexcept
-> const VersionInfo & {
return this->version_info;
};
[[nodiscard]] auto CreateTransaction() const -> std::unique_ptr<Transaction>;
private:
/// GRPC-Channel (HTTP/2 Connection plus Authentication). We use a shared
/// pointer because Transaction instances also own the channel.
std::shared_ptr<grpc::Channel> channel;
/// Service for retrieving the server's version. We use a unique pointer
/// because only this connection owns and uses this service.
std::unique_ptr<GeneralInfoService::Stub> general_info_service;
/// The server's version. It's mutable because it is rather a cache than a
/// data member which is subject to change.
mutable VersionInfo version_info;
/// Service for entity transactions. We use a shared pointer because
/// Transaction instances also own this service stub.
std::shared_ptr<EntityTransactionService::Stub> entity_transaction_service;
};
/**
Loading