From e8a9df96a084dc8c34d928a63e8fedbcb2eec9b6 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 29 Feb 2024 15:17:26 +0100 Subject: just-mr and serve: Extend use of noexcept specifier The just serve client-side and API methods, as well as just-mr utilities should use the noexcept specifier. --- .../serve_api/remote/configuration_client.cpp | 86 ++++++++++++---------- 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'src/buildtool/serve_api/remote/configuration_client.cpp') diff --git a/src/buildtool/serve_api/remote/configuration_client.cpp b/src/buildtool/serve_api/remote/configuration_client.cpp index 032e548f..dcc7d31a 100644 --- a/src/buildtool/serve_api/remote/configuration_client.cpp +++ b/src/buildtool/serve_api/remote/configuration_client.cpp @@ -14,13 +14,14 @@ #include "src/buildtool/serve_api/remote/configuration_client.hpp" +#include #include #include "nlohmann/json.hpp" #include "src/buildtool/execution_api/remote/config.hpp" #include "src/buildtool/serve_api/remote/config.hpp" -auto ConfigurationClient::CheckServeRemoteExecution() -> bool { +auto ConfigurationClient::CheckServeRemoteExecution() noexcept -> bool { auto client_remote_address = RemoteExecutionConfig::RemoteAddress(); if (!client_remote_address) { logger_.Emit(LogLevel::Error, @@ -46,49 +47,60 @@ auto ConfigurationClient::CheckServeRemoteExecution() -> bool { LogStatus(&logger_, LogLevel::Error, status); return false; } - auto client_msg = client_remote_address->ToJson().dump(); - std::string serve_msg{}; - if (response.address().empty()) { - // just serve acts as just execute, so from the server's perspective - // there is nothing to be checked and it's the client's job to ensure - // that its remote execution and serve endpoints match - // - // NOTE: This check might make sense to be removed altogether in the - // future, or updated to (at most) a warning. - if (client_remote_address->ToJson() == client_serve_address->ToJson()) { - return true; - } - serve_msg = client_serve_address->ToJson().dump(); - } - else { - nlohmann::json serve_remote_endpoint{}; - try { - serve_remote_endpoint = nlohmann::json::parse(response.address()); - } catch (std::exception const& ex) { - logger_.Emit( - LogLevel::Error, - "Parsing configured address from response failed with:\n{}", - ex.what()); + try { + auto client_msg = client_remote_address->ToJson().dump(); + std::string serve_msg{}; + + if (response.address().empty()) { + // just serve acts as just execute, so from the server's perspective + // there is nothing to be checked and it's the client's job to + // ensure that its remote execution and serve endpoints match + // + // NOTE: This check might make sense to be removed altogether in the + // future, or updated to (at most) a warning. + if (client_remote_address->ToJson() == + client_serve_address->ToJson()) { + return true; + } + serve_msg = client_serve_address->ToJson().dump(); } - if (serve_remote_endpoint == client_remote_address->ToJson()) { - return true; + else { + nlohmann::json serve_remote_endpoint{}; + try { + serve_remote_endpoint = + nlohmann::json::parse(response.address()); + } catch (std::exception const& ex) { + logger_.Emit( + LogLevel::Error, + "Parsing configured address from response failed with:\n{}", + ex.what()); + } + if (serve_remote_endpoint == client_remote_address->ToJson()) { + return true; + } + serve_msg = serve_remote_endpoint.dump(); } - serve_msg = serve_remote_endpoint.dump(); + // log any mismatch found + logger_.Emit( + LogLevel::Error, + "Different execution endpoint detected!\nIn order to correctly use " + "the serve service, its remote execution endpoint must be the same " + "used by the client.\nserve remote endpoint: {}\nclient remote " + "endpoint: {}", + serve_msg, + client_msg); + + } catch (std::exception const& ex) { + logger_.Emit( + LogLevel::Error, + "parsing response for remote endpoint request failed with:\n{}", + ex.what()); } - // log any mismatch found - logger_.Emit( - LogLevel::Error, - "Different execution endpoint detected!\nIn order to correctly use " - "the serve service, its remote execution endpoint must be the same " - "used by the client.\nserve remote endpoint: {}\nclient remote " - "endpoint: {}", - serve_msg, - client_msg); return false; } -auto ConfigurationClient::IsCompatible() -> std::optional { +auto ConfigurationClient::IsCompatible() noexcept -> std::optional { grpc::ClientContext context; justbuild::just_serve::CompatibilityRequest request{}; justbuild::just_serve::CompatibilityResponse response{}; -- cgit v1.2.3