diff --git a/conanfile.py b/conanfile.py index 7428fc8b0cdc2e40db719e3755c00f305a742f93..b1078152092c1859d5e1a866cb17ea6bb492540b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -37,9 +37,14 @@ class LinkAheadConan(ConanFile): self.tool_requires("cmake/[>=3.13]") self.tool_requires("boost/1.80.0") self.test_requires("gtest/1.11.0") - self.requires("grpc/1.48.4") - self.requires("protobuf/3.21.12") - self.requires("boost/1.80.0") + + def requirements(self): + self.requires("grpc/1.48.4", transitive_headers=True, transitive_libs=True) + self.requires("protobuf/3.21.12", transitive_headers=True, transitive_libs=True) + self.requires("boost/1.80.0", transitive_headers=True, transitive_libs=True) + + def test_requirements(self): + self.test_requires("gtest/1.11.0") def config_options(self): if self.settings.os == "Windows": diff --git a/src/cxxlinkaheadcli.cpp b/src/cxxlinkaheadcli.cpp index 8b3b7f918505fa1c4613614eb1dd26f7dcb491b4..3626d96835d6447d60e8df3a53370099b3eabe8d 100644 --- a/src/cxxlinkaheadcli.cpp +++ b/src/cxxlinkaheadcli.cpp @@ -43,20 +43,27 @@ const auto logger_name = "liblinkahead"; auto main() -> int { - std::cout << "LinkAhead C++ client (liblinkahead " << linkahead::LIBLINKAHEAD_VERSION_MINOR << "." + std::cout << "LinkAhead C++ client (liblinkahead " << linkahead::LIBLINKAHEAD_VERSION_MAJOR << "." << linkahead::LIBLINKAHEAD_VERSION_MINOR << "." << linkahead::LIBLINKAHEAD_VERSION_PATCH - << ")\n" - << std::endl; + << ")\n"; try { const auto &connection = linkahead::connection::ConnectionManager::GetDefaultConnection(); - connection->RetrieveVersionInfoNoExceptions(); + auto status = connection->RetrieveVersionInfoNoExceptions(); + if (status.GetCode() == linkahead::CONNECTION_ERROR) { + const auto connection_config = + linkahead::configuration::ConfigurationManager::GetDefaultConnectionConfiguration(); + std::cout << "ConnectionError: Cannot connect to " << connection_config->GetHost() << ":" + << connection_config->GetPort() << '\n'; + + return 1; + } // get version info of the server const auto &v_info = connection->GetVersionInfo(); std::cout << "Server Version: " << v_info->GetMajor() << "." << v_info->GetMinor() << "." << v_info->GetPatch() << "-" << v_info->GetPreRelease() << "-" << v_info->GetBuild() - << std::endl; + << '\n'; // retrieve an entity auto transaction(connection->CreateTransaction()); @@ -67,12 +74,12 @@ auto main() -> int { << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); const auto &result_set = transaction->GetResultSet(); for (const auto &entity : result_set) { - std::cout << entity.ToString() << std::endl; + std::cout << entity.ToString() << '\n'; } // execute a query std::string query("FIND Property \"Prop *\""); - std::cout << "Trying to execute a query:\n" << query << std::endl; + std::cout << "Trying to execute a query:\n" << query << '\n'; auto q_transaction(connection->CreateTransaction()); q_transaction->Query(query); q_transaction->ExecuteAsynchronously(); @@ -81,18 +88,18 @@ auto main() -> int { << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); const auto &result_set_2 = q_transaction->GetResultSet(); for (const auto &entity : result_set_2) { - std::cout << entity.ToString() << std::endl; + std::cout << entity.ToString() << '\n'; } return 0; } catch (const linkahead::exceptions::ConfigurationError &exc) { - std::cout << "ConfigurationError: " << exc.what() << std::endl; + std::cout << "ConfigurationError: " << exc.what() << '\n'; return exc.GetCode(); } catch (const std::exception &exc) { - std::cout << "Exception: " << exc.what() << std::endl; + std::cout << "Exception: " << exc.what() << '\n'; return 1; } catch (...) { - std::cout << "Some other exception." << std::endl; + std::cout << "Some other exception." << '\n'; return 2; } } diff --git a/src/linkahead/utility.cpp b/src/linkahead/utility.cpp index fe229d16976c5abd9b9090bb06de7c67917248b1..21521ecd83fc3de4e334254d3c912bb7dc687997 100644 --- a/src/linkahead/utility.cpp +++ b/src/linkahead/utility.cpp @@ -108,6 +108,10 @@ template <> auto getEnumValueFromName<Role>(const std::string &name) -> Role { auto load_string_file(const path &file_path) -> std::string { std::string result; + if (!exists(file_path)) { + throw std::runtime_error("File not found: " + file_path.string()); + } + // adapted from boost::filesystem::load_string_file, which was removed in 1.84 std::ifstream file; file.exceptions(std::ios_base::failbit | std::ios_base::badbit);