From e8085c1c209e98a31c32e2032d02d620449006e4 Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 2 Oct 2024 12:28:17 +0200 Subject: Enable bugprone-unhandled-exception-at-new check. --- src/buildtool/execution_api/local/local_action.cpp | 39 ++++++++++++++++------ src/buildtool/execution_api/local/local_api.hpp | 4 ++- .../execution_api/remote/bazel/bazel_action.cpp | 33 ++++++++++++++---- .../execution_api/remote/bazel/bazel_api.cpp | 4 ++- 4 files changed, 62 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index 10359e92..e2ee373c 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -104,16 +104,33 @@ auto LocalAction::Execute(Logger const* logger) noexcept action->hash()); } + auto create_response = [](Logger const* logger, + std::string const& action_hash, + auto&&... args) -> IExecutionResponse::Ptr { + try { + return IExecutionResponse::Ptr{new LocalResponse{ + action_hash, std::forward(args)...}}; + } catch (...) { + if (logger != nullptr) { + logger->Emit(LogLevel::Error, + "failed to create a response for {}", + action_hash); + } + } + return nullptr; + }; + if (do_cache) { if (auto result = local_context_.storage->ActionCache().CachedResult(*action)) { if (result->exit_code() == 0 and ActionResultContainsExpectedOutputs( *result, output_files_, output_dirs_)) { - return IExecutionResponse::Ptr{ - new LocalResponse{action->hash(), - {std::move(*result), /*is_cached=*/true}, - local_context_.storage}}; + return create_response( + logger, + action->hash(), + LocalAction::Output{*std::move(result), /*is_cached=*/true}, + local_context_.storage); } } } @@ -135,13 +152,15 @@ auto LocalAction::Execute(Logger const* logger) noexcept } output->is_cached = true; - return IExecutionResponse::Ptr{ - new LocalResponse{action_cached->hash(), - std::move(*output), - local_context_.storage}}; + return create_response(logger, + action_cached->hash(), + *std::move(output), + local_context_.storage); } - return IExecutionResponse::Ptr{new LocalResponse{ - action->hash(), std::move(*output), local_context_.storage}}; + return create_response(logger, + action->hash(), + *std::move(output), + local_context_.storage); } } diff --git a/src/buildtool/execution_api/local/local_api.hpp b/src/buildtool/execution_api/local/local_api.hpp index 4fc6b16e..e564d72f 100644 --- a/src/buildtool/execution_api/local/local_api.hpp +++ b/src/buildtool/execution_api/local/local_api.hpp @@ -19,6 +19,7 @@ #include #include #include +#include // std::nothrow #include #include #include @@ -67,7 +68,8 @@ class LocalApi final : public IExecutionApi { std::map const& env_vars, std::map const& properties) const noexcept -> IExecutionAction::Ptr final { - return IExecutionAction::Ptr{new LocalAction{&local_context_, + return IExecutionAction::Ptr{new (std::nothrow) + LocalAction{&local_context_, root_digest, command, cwd, diff --git a/src/buildtool/execution_api/remote/bazel/bazel_action.cpp b/src/buildtool/execution_api/remote/bazel/bazel_action.cpp index 15ca949f..f805c6fc 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_action.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_action.cpp @@ -69,6 +69,22 @@ auto BazelAction::Execute(Logger const* logger) noexcept action->hash()); } + auto create_response = [](Logger const* logger, + std::string const& action_hash, + auto&&... args) -> IExecutionResponse::Ptr { + try { + return IExecutionResponse::Ptr{new BazelResponse{ + action_hash, std::forward(args)...}}; + } catch (...) { + if (logger != nullptr) { + logger->Emit(LogLevel::Error, + "failed to create a response for {}", + action_hash); + } + } + return nullptr; + }; + if (do_cache) { if (auto result = network_->GetCachedActionResult(*action, output_files_)) { @@ -77,8 +93,11 @@ auto BazelAction::Execute(Logger const* logger) noexcept *result, output_files_, output_dirs_) ) { - return IExecutionResponse::Ptr{new BazelResponse{ - action->hash(), network_, {*result, true}}}; + return create_response( + logger, + action->hash(), + network_, + BazelExecutionClient::ExecutionOutput{*result, true}); } } } @@ -101,11 +120,13 @@ auto BazelAction::Execute(Logger const* logger) noexcept } output->cached_result = true; - return IExecutionResponse::Ptr{new BazelResponse{ - action_cached->hash(), network_, std::move(*output)}}; + return create_response(logger, + action_cached->hash(), + network_, + *std::move(output)); } - return IExecutionResponse::Ptr{new BazelResponse{ - action->hash(), network_, std::move(*output)}}; + return create_response( + logger, action->hash(), network_, *std::move(output)); } } diff --git a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp index 8dbd026e..1b2933af 100644 --- a/src/buildtool/execution_api/remote/bazel/bazel_api.cpp +++ b/src/buildtool/execution_api/remote/bazel/bazel_api.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -218,7 +219,8 @@ auto BazelApi::CreateAction( std::map const& env_vars, std::map const& properties) const noexcept -> IExecutionAction::Ptr { - return std::unique_ptr{new BazelAction{network_, + return std::unique_ptr{new (std::nothrow) + BazelAction{network_, root_digest, command, cwd, -- cgit v1.2.3