From 72fb5958427ef63181023e8fedce5c6ba642b01a Mon Sep 17 00:00:00 2001 From: Maksim Denisov Date: Wed, 2 Oct 2024 17:39:13 +0200 Subject: Enable bugprone-empty-catch check. --- src/buildtool/file_system/file_root.hpp | 48 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 27 deletions(-) (limited to 'src/buildtool/file_system/file_root.hpp') diff --git a/src/buildtool/file_system/file_root.hpp b/src/buildtool/file_system/file_root.hpp index 6a34409c..82e30b89 100644 --- a/src/buildtool/file_system/file_root.hpp +++ b/src/buildtool/file_system/file_root.hpp @@ -185,23 +185,14 @@ class FileRoot { [[nodiscard]] auto ContainsBlob(std::string const& name) const noexcept -> bool { - try { - if (std::holds_alternative(data_)) { - auto const& data = std::get(data_); - auto ptr = data->LookupEntryByName(name); - if (static_cast(ptr)) { - return IsBlobObject(ptr->Type()); - } - return false; - } - if (std::holds_alternative(data_)) { - auto const& data = std::get(data_); - auto it = data.find(name); - return (it != data.end() and IsBlobObject(it->second)); - } - } catch (...) { + if (auto const* const data = std::get_if(&data_)) { + auto const ptr = (*data)->LookupEntryByName(name); + return ptr != nullptr and IsBlobObject(ptr->Type()); + } + if (auto const* const data = std::get_if(&data_)) { + auto const it = data->find(name); + return it != data->end() and IsBlobObject(it->second); } - return false; } @@ -339,18 +330,21 @@ class FileRoot { std::string const& git_tree_id, bool ignore_special = false) noexcept -> std::optional { - if (auto cas = GitCAS::Open(repo_path)) { - if (auto tree = GitTree::Read(cas, git_tree_id, ignore_special)) { - try { - return FileRoot{ - cas, - std::make_shared(std::move(*tree)), - ignore_special}; - } catch (...) { - } - } + auto cas = GitCAS::Open(repo_path); + if (not cas) { + return std::nullopt; + } + auto tree = GitTree::Read(cas, git_tree_id, ignore_special); + if (not tree) { + return std::nullopt; + } + try { + return FileRoot{cas, + std::make_shared(std::move(*tree)), + ignore_special}; + } catch (...) { + return std::nullopt; } - return std::nullopt; } /// \brief Return a complete description of the content of this root, if -- cgit v1.2.3