From 7bc00b40a22f8b925219dc12110693a38cba67e0 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 5 Jun 2025 09:55:17 +0200 Subject: GitRepo: Ensure compliance with existing noexcept specifiers ...while also removing some unneeded one. Do not implicitly trust that the third-party code called in these methods is non-throwing and instead properly handle any exception that might arise. Also remove the specifiers from some anonymous namespace methods where a try-catch would be overkill and let their callers handle any exceptions instead. --- src/buildtool/file_system/git_repo.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src/buildtool/file_system/git_repo.cpp') diff --git a/src/buildtool/file_system/git_repo.cpp b/src/buildtool/file_system/git_repo.cpp index b19dfe3e..d5ae6e3d 100644 --- a/src/buildtool/file_system/git_repo.cpp +++ b/src/buildtool/file_system/git_repo.cpp @@ -55,7 +55,7 @@ std::unordered_set const kNonSpecialGitFileModes{ GIT_FILEMODE_BLOB_EXECUTABLE, GIT_FILEMODE_TREE}; -[[nodiscard]] auto ToHexString(git_oid const& oid) noexcept +[[nodiscard]] auto ToHexString(git_oid const& oid) -> std::optional { std::string hex_id(GIT_OID_HEXSZ, '\0'); if (git_oid_fmt(hex_id.data(), &oid) != 0) { @@ -99,7 +99,7 @@ std::unordered_set const kNonSpecialGitFileModes{ } } -[[nodiscard]] auto GitTypeToObjectType(git_object_t const& type) noexcept +[[nodiscard]] auto GitTypeToObjectType(git_object_t const& type) -> std::optional { switch (type) { case GIT_OBJECT_BLOB: @@ -154,8 +154,7 @@ std::unordered_set const kNonSpecialGitFileModes{ [[nodiscard]] auto flat_tree_walker_ignore_special(const char* /*root*/, const git_tree_entry* entry, - void* payload) noexcept - -> int { + void* payload) -> int { auto* entries = reinterpret_cast(payload); // NOLINT @@ -180,7 +179,7 @@ std::unordered_set const kNonSpecialGitFileModes{ [[nodiscard]] auto flat_tree_walker(const char* /*root*/, const git_tree_entry* entry, - void* payload) noexcept -> int { + void* payload) -> int { auto* entries = reinterpret_cast(payload); // NOLINT @@ -1640,10 +1639,17 @@ auto GitRepo::LocalFetchViaTmpRepo(StorageConfig const& storage_config, auto GitRepo::GetConfigSnapshot() const noexcept -> std::shared_ptr { #ifndef BOOTSTRAP_BUILD_TOOL - git_config* cfg_ptr{nullptr}; - if (git_repository_config_snapshot(&cfg_ptr, git_cas_->GetRepository()) == - 0) { - return std::shared_ptr(cfg_ptr, config_closer); + try { + git_config* cfg_ptr{nullptr}; + if (git_repository_config_snapshot(&cfg_ptr, + git_cas_->GetRepository()) == 0) { + return std::shared_ptr(cfg_ptr, config_closer); + } + } catch (std::exception const& ex) { + Logger::Log( + LogLevel::Debug, + "Unexpected failure getting Git configuration snapshot:\n{}", + ex.what()); } #endif // BOOTSTRAP_BUILD_TOOL return nullptr; -- cgit v1.2.3