diff options
Diffstat (limited to 'src/buildtool/execution_api')
-rw-r--r-- | src/buildtool/execution_api/common/tree_reader_utils.cpp | 29 | ||||
-rw-r--r-- | src/buildtool/execution_api/git/git_api.hpp | 61 |
2 files changed, 47 insertions, 43 deletions
diff --git a/src/buildtool/execution_api/common/tree_reader_utils.cpp b/src/buildtool/execution_api/common/tree_reader_utils.cpp index a04b9300..5a55c059 100644 --- a/src/buildtool/execution_api/common/tree_reader_utils.cpp +++ b/src/buildtool/execution_api/common/tree_reader_utils.cpp @@ -64,7 +64,7 @@ namespace { } template <typename TTree> -[[nodiscard]] auto TreeToString(TTree const& entries) noexcept +[[nodiscard]] auto TreeToString(TTree const& entries) -> std::optional<std::string> { auto json = nlohmann::json::object(); TreeReaderUtils::InfoStoreFunc store_infos = @@ -78,14 +78,7 @@ template <typename TTree> }; if (TreeReaderUtils::ReadObjectInfos(entries, store_infos)) { - try { - return json.dump(2) + "\n"; - } catch (std::exception const& ex) { - Logger::Log(LogLevel::Error, - "dumping Directory to string failed with:\n{}", - ex.what()); - return std::nullopt; - } + return json.dump(2) + "\n"; } Logger::Log(LogLevel::Error, "reading object infos from Directory failed"); return std::nullopt; @@ -164,11 +157,25 @@ auto TreeReaderUtils::ReadObjectInfos(GitRepo::tree_entries_t const& entries, auto TreeReaderUtils::DirectoryToString(bazel_re::Directory const& dir) noexcept -> std::optional<std::string> { - return TreeToString(dir); + try { + return TreeToString(dir); + } catch (const std::exception& e) { + Logger::Log(LogLevel::Error, + "An error occurred while reading bazel:re::Directory:\n", + e.what()); + return std::nullopt; + } } auto TreeReaderUtils::GitTreeToString( GitRepo::tree_entries_t const& entries) noexcept -> std::optional<std::string> { - return TreeToString(entries); + try { + return TreeToString(entries); + } catch (const std::exception& e) { + Logger::Log(LogLevel::Error, + "An error occurred while reading git tree:\n{}", + e.what()); + return std::nullopt; + } } diff --git a/src/buildtool/execution_api/git/git_api.hpp b/src/buildtool/execution_api/git/git_api.hpp index ed28f237..1c7edca0 100644 --- a/src/buildtool/execution_api/git/git_api.hpp +++ b/src/buildtool/execution_api/git/git_api.hpp @@ -115,8 +115,9 @@ class GitApi final : public IExecutionApi { return false; } for (std::size_t i{}; i < artifacts_info.size(); ++i) { - auto fd = fds[i]; auto const& info = artifacts_info[i]; + + std::string content; if (IsTreeObject(info.type) and not raw_tree) { auto tree = repo_config_->ReadTreeFromGitCAS(info.digest.hash()); @@ -126,27 +127,22 @@ class GitApi final : public IExecutionApi { info.digest.hash()); return false; } - auto json = nlohmann::json::object(); - for (auto const& [path, entry] : *tree) { - auto digest = ToArtifactDigest(*entry); - if (not digest) { - return false; + + try { + auto json = nlohmann::json::object(); + for (auto const& [path, entry] : *tree) { + auto digest = ToArtifactDigest(*entry); + if (not digest) { + return false; + } + json[path] = + Artifact::ObjectInfo{.digest = *std::move(digest), + .type = entry->Type(), + .failed = false} + .ToString(/*size_unknown*/ true); } - json[path] = - Artifact::ObjectInfo{.digest = *std::move(digest), - .type = entry->Type(), - .failed = false} - .ToString(/*size_unknown*/ true); - } - auto msg = json.dump(2) + "\n"; - if (gsl::owner<FILE*> out = fdopen(fd, "wb")) { // NOLINT - std::fwrite(msg.data(), 1, msg.size(), out); - std::fclose(out); - } - else { - Logger::Log(LogLevel::Error, - "dumping to file descriptor {} failed.", - fd); + content = json.dump(2) + "\n"; + } catch (...) { return false; } } @@ -159,17 +155,18 @@ class GitApi final : public IExecutionApi { info.digest.hash()); return false; } - auto msg = *blob; - if (gsl::owner<FILE*> out = fdopen(fd, "wb")) { // NOLINT - std::fwrite(msg.data(), 1, msg.size(), out); - std::fclose(out); - } - else { - Logger::Log(LogLevel::Error, - "dumping to file descriptor {} failed.", - fd); - return false; - } + content = *std::move(blob); + } + + if (gsl::owner<FILE*> out = fdopen(fds[i], "wb")) { // NOLINT + std::fwrite(content.data(), 1, content.size(), out); + std::fclose(out); + } + else { + Logger::Log(LogLevel::Error, + "dumping to file descriptor {} failed.", + fds[i]); + return false; } } return true; |