From 6e74b1448bf8d94d73ef3134aa9e8bf36e51a2aa Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 2 Oct 2024 16:03:45 +0200 Subject: Enable bugprone-exception-escape check --- .../execution_api/common/tree_reader_utils.cpp | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/buildtool/execution_api/common/tree_reader_utils.cpp') 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 -[[nodiscard]] auto TreeToString(TTree const& entries) noexcept +[[nodiscard]] auto TreeToString(TTree const& entries) -> std::optional { auto json = nlohmann::json::object(); TreeReaderUtils::InfoStoreFunc store_infos = @@ -78,14 +78,7 @@ template }; 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 { - 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 { - 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; + } } -- cgit v1.2.3