diff --git a/src/FeatureIssues.cpp b/src/FeatureIssues.cpp index efd8fd0893..2a91a20835 100644 --- a/src/FeatureIssues.cpp +++ b/src/FeatureIssues.cpp @@ -1358,11 +1358,15 @@ namespace FeatureIssues for (const auto& testInfo : testInis) { try { if (testInfo.isNewFile) { - // Remove the test INI file we created - if (std::filesystem::exists(testInfo.testIniPath)) { - std::filesystem::remove(testInfo.testIniPath); - logger::debug("Removed test INI: {}", testInfo.testIniPath); - } + // Remove the test INI file we created. + std::error_code ec; // Use the error_code overload to avoid exceptions for non-critical errors like the file not existing. + if (const bool removed = std::filesystem::remove(testInfo.testIniPath, ec); ec) { + logger::warn("Error while trying to delete {}: {}", testInfo.testIniPath, ec.message()); + success = false; + } else if (removed) { + // Successfully deleted. + logger::debug("Deleted {}", testInfo.testIniPath); + } // If !removed and no error, the file didn't exist, which is fine. } else { // Restore original version using INI functions CSimpleIniA ini; @@ -1395,13 +1399,17 @@ namespace FeatureIssues } } // Clear the active test INIs tracking and remove persistent state s_activeTestInis.clear(); + const auto stateFilePath = GetTestStateFilePath(); + const auto& stateFilePathString = Util::WStringToString(stateFilePath); try { - const auto stateFilePath = GetTestStateFilePath(); - if (std::filesystem::exists(stateFilePath)) { - std::filesystem::remove(stateFilePath); + bool removed = std::filesystem::remove(stateFilePath); + if (!removed) { + logger::warn("Failed to delete file {}", stateFilePathString); + } else { + logger::debug("Deleted {}", stateFilePathString); } } catch (const std::exception& e) { - logger::warn("Failed to remove persistent test state file: {}", e.what()); + logger::warn("Expected to delete {}, but ran into exception: {}", stateFilePathString, e.what()); } // Clear existing feature issues and rescan to update UI immediately // This ensures the restored state is reflected without requiring a restart diff --git a/src/ShaderCache.cpp b/src/ShaderCache.cpp index 5b4e94aec6..c02199dc86 100644 --- a/src/ShaderCache.cpp +++ b/src/ShaderCache.cpp @@ -1923,16 +1923,12 @@ namespace SIE const auto& filePathString = Util::WStringToString(filePath); { std::scoped_lock lockD{ compilationSet.compilationMutex }; - try { - if (std::filesystem::exists(filePath)) { - std::filesystem::remove(filePath); - logger::debug("Deleted {}", filePathString); - } - } catch (const std::exception& e) { - logger::warn("Failed to delete file {}: {}", filePathString, e.what()); - } catch (...) { - logger::warn("An unknown error occurred while trying to delete file '{}'", filePathString); - } + std::error_code ec; // Use the error_code overload to avoid exceptions for non-critical errors like the file not existing. + if (const bool removed = std::filesystem::remove(filePath, ec); ec) { + logger::warn("Error while trying to delete {}: {}", filePathString, ec.message()); + } else if (removed) { + logger::debug("Deleted {}", filePathString); + } // If !removed and no error, the file didn't exist, which is fine. } logger::debug("Marking recompile for shader: {}", entry.key);