From ab0a06871391a84c9b904bc9f2cd74ee1e8903ea Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Tue, 14 May 2024 14:44:29 +0200 Subject: serve target: Improve logic for local build failure triggers If the serve endpoint reports an internal error, local builds should not continue and the error message should be provided. Similarly, if the serve endpoint promises the target cache value to be in remote CAS, but the client cannot find or process it as needed, then a local build again should not continue and the reason be provided as an error message. --- src/buildtool/serve_api/remote/target_client.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/buildtool/serve_api/remote/target_client.cpp') diff --git a/src/buildtool/serve_api/remote/target_client.cpp b/src/buildtool/serve_api/remote/target_client.cpp index d64f24c8..67b50a84 100644 --- a/src/buildtool/serve_api/remote/target_client.cpp +++ b/src/buildtool/serve_api/remote/target_client.cpp @@ -100,10 +100,6 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, grpc::ClientContext context; justbuild::just_serve::ServeTargetResponse response; auto const& status = stub_->ServeTarget(&context, request, &response); - if (!status.ok()) { - return serve_target_result_t{std::in_place_index<1>, - StatusString(status)}; - } // differentiate status codes switch (status.error_code()) { @@ -145,7 +141,7 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, auto const& result = TargetCacheEntry::FromJson( nlohmann::json::parse(*target_value_str)); // return the target cache value information - return serve_target_result_t{std::in_place_index<2>, + return serve_target_result_t{std::in_place_index<3>, std::make_pair(result, obj_info)}; } catch (std::exception const& ex) { return serve_target_result_t{ @@ -154,13 +150,20 @@ auto TargetClient::ServeTarget(const TargetCacheKey& key, ex.what())}; } } + case grpc::StatusCode::INTERNAL: { + return serve_target_result_t{ + std::in_place_index<1>, + fmt::format( + "Serve endpoint reported the fatal internal error:\n{}", + status.error_message())}; + } case grpc::StatusCode::NOT_FOUND: { return std::nullopt; // this might allow a local build to continue } default:; // fallthrough } return serve_target_result_t{ - std::in_place_index<1>, + std::in_place_index<2>, fmt::format("Serve endpoint failed with:\n{}", status.error_message())}; } -- cgit v1.2.3