Skip to content
Snippets Groups Projects
Commit 6d639beb authored by Joscha Schmiedt's avatar Joscha Schmiedt
Browse files

Better error checking and reporting in cxxilnkahaedcli

parent 3a7fbc79
No related branches found
No related tags found
2 merge requests!61Release 0.3.0,!59F better errors
Pipeline #56923 passed with warnings
Pipeline: caosdb-cppinttest

#56925

    ...@@ -43,20 +43,27 @@ const auto logger_name = "liblinkahead"; ...@@ -43,20 +43,27 @@ const auto logger_name = "liblinkahead";
    auto main() -> int { 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 << linkahead::LIBLINKAHEAD_VERSION_MINOR << "." << linkahead::LIBLINKAHEAD_VERSION_PATCH
    << ")\n" << ")\n";
    << std::endl;
    try { try {
    const auto &connection = linkahead::connection::ConnectionManager::GetDefaultConnection(); 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 // get version info of the server
    const auto &v_info = connection->GetVersionInfo(); const auto &v_info = connection->GetVersionInfo();
    std::cout << "Server Version: " << v_info->GetMajor() << "." << v_info->GetMinor() << "." std::cout << "Server Version: " << v_info->GetMajor() << "." << v_info->GetMinor() << "."
    << v_info->GetPatch() << "-" << v_info->GetPreRelease() << "-" << v_info->GetBuild() << v_info->GetPatch() << "-" << v_info->GetPreRelease() << "-" << v_info->GetBuild()
    << std::endl; << '\n';
    // retrieve an entity // retrieve an entity
    auto transaction(connection->CreateTransaction()); auto transaction(connection->CreateTransaction());
    ...@@ -67,12 +74,12 @@ auto main() -> int { ...@@ -67,12 +74,12 @@ auto main() -> int {
    << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription();
    const auto &result_set = transaction->GetResultSet(); const auto &result_set = transaction->GetResultSet();
    for (const auto &entity : result_set) { for (const auto &entity : result_set) {
    std::cout << entity.ToString() << std::endl; std::cout << entity.ToString() << '\n';
    } }
    // execute a query // execute a query
    std::string query("FIND Property \"Prop *\""); 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()); auto q_transaction(connection->CreateTransaction());
    q_transaction->Query(query); q_transaction->Query(query);
    q_transaction->ExecuteAsynchronously(); q_transaction->ExecuteAsynchronously();
    ...@@ -81,18 +88,18 @@ auto main() -> int { ...@@ -81,18 +88,18 @@ auto main() -> int {
    << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription(); << "status: " << t_stat.GetCode() << " // " << t_stat.GetDescription();
    const auto &result_set_2 = q_transaction->GetResultSet(); const auto &result_set_2 = q_transaction->GetResultSet();
    for (const auto &entity : result_set_2) { for (const auto &entity : result_set_2) {
    std::cout << entity.ToString() << std::endl; std::cout << entity.ToString() << '\n';
    } }
    return 0; return 0;
    } catch (const linkahead::exceptions::ConfigurationError &exc) { } catch (const linkahead::exceptions::ConfigurationError &exc) {
    std::cout << "ConfigurationError: " << exc.what() << std::endl; std::cout << "ConfigurationError: " << exc.what() << '\n';
    return exc.GetCode(); return exc.GetCode();
    } catch (const std::exception &exc) { } catch (const std::exception &exc) {
    std::cout << "Exception: " << exc.what() << std::endl; std::cout << "Exception: " << exc.what() << '\n';
    return 1; return 1;
    } catch (...) { } catch (...) {
    std::cout << "Some other exception." << std::endl; std::cout << "Some other exception." << '\n';
    return 2; return 2;
    } }
    } }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment