From dbeda9835c4d1456b89524112823734ec8ebde02 Mon Sep 17 00:00:00 2001 From: Roushan Singh Date: Thu, 6 Mar 2025 12:22:52 +0530 Subject: [PATCH 1/4] chore: resolve warnings, handle nodiscard, and add error logging --- engine/controllers/process_manager.cc | 8 +++++++- engine/services/hardware_service.cc | 9 ++++++++- engine/utils/command_executor.h | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/engine/controllers/process_manager.cc b/engine/controllers/process_manager.cc index 9d1604754..72b0f08d2 100644 --- a/engine/controllers/process_manager.cc +++ b/engine/controllers/process_manager.cc @@ -9,7 +9,13 @@ void ProcessManager::destroy( std::function&& callback) { auto loaded_engines = engine_service_->GetSupportedEngineNames(); for (const auto& engine : loaded_engines.value()) { - engine_service_->UnloadEngine(engine); + auto result = engine_service_->UnloadEngine(engine); + if (!result) { + // Handle the error if any. + // Log the Error + LOG_ERROR << "Error unloading engine: " << result.error(); + continue; + } } app().quit(); Json::Value ret; diff --git a/engine/services/hardware_service.cc b/engine/services/hardware_service.cc index e6bcc89ef..f4c2819c1 100644 --- a/engine/services/hardware_service.cc +++ b/engine/services/hardware_service.cc @@ -304,7 +304,14 @@ void HardwareService::UpdateHardwareInfos() { }; for (auto const& he : b.value()) { if (!exists(he.uuid)) { - db_service_->DeleteHardwareEntry(he.uuid); + auto result = db_service_->DeleteHardwareEntry(he.uuid); + if (!result) { + // Handle the error if any. + // Log the Error + LOG_ERROR << "Error deleting hardware entry " << he.uuid << ": " + << result.error(); + continue; + } } } diff --git a/engine/utils/command_executor.h b/engine/utils/command_executor.h index 87460e2c1..6d534bbc3 100644 --- a/engine/utils/command_executor.h +++ b/engine/utils/command_executor.h @@ -20,7 +20,7 @@ class CommandExecutor { if (!pipe) { throw std::runtime_error("popen() failed!"); } - m_pipe = std::unique_ptr(pipe, PCLOSE); + m_pipe = std::unique_ptr(pipe, [](FILE* file) { if (file) { pclose(file); } }); } CommandExecutor(const CommandExecutor&) = delete; @@ -45,5 +45,5 @@ class CommandExecutor { } private: - std::unique_ptr m_pipe{nullptr, PCLOSE}; + std::unique_ptr m_pipe{nullptr, [](FILE* file) { if (file) { pclose(file); } }}; }; From 1da8d2b73ae902c84af9fa4d165110c1c17af678 Mon Sep 17 00:00:00 2001 From: Roushan Kumar Singh <158602016+github-roushan@users.noreply.github.com> Date: Fri, 7 Mar 2025 16:56:17 +0530 Subject: [PATCH 2/4] Update command_executor.h use macro PCLOSE to correctly map to _pclose on windows --- engine/utils/command_executor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/utils/command_executor.h b/engine/utils/command_executor.h index 6d534bbc3..da3196390 100644 --- a/engine/utils/command_executor.h +++ b/engine/utils/command_executor.h @@ -7,7 +7,7 @@ #ifdef _WIN32 #define POPEN _popen -#define PCLOSE _pclose +#define PCLOSE windo #else #define POPEN popen #define PCLOSE pclose @@ -20,7 +20,7 @@ class CommandExecutor { if (!pipe) { throw std::runtime_error("popen() failed!"); } - m_pipe = std::unique_ptr(pipe, [](FILE* file) { if (file) { pclose(file); } }); + m_pipe = std::unique_ptr(pipe, [](FILE* file) { if (file) { PCLOSE(file); } }); } CommandExecutor(const CommandExecutor&) = delete; @@ -45,5 +45,5 @@ class CommandExecutor { } private: - std::unique_ptr m_pipe{nullptr, [](FILE* file) { if (file) { pclose(file); } }}; + std::unique_ptr m_pipe{nullptr, [](FILE* file) { if (file) { PCLOSE(file); } }}; }; From 08af92ce7ba5c112c2f9063d58445750dc3ef27a Mon Sep 17 00:00:00 2001 From: Roushan Kumar Singh <158602016+github-roushan@users.noreply.github.com> Date: Sat, 8 Mar 2025 22:48:49 +0530 Subject: [PATCH 3/4] fix typo: revert PCLOSE to _pclose for windows The PCLOSE macro was mistakenly defined as pclose for Windows. This commit fixes the typo, reverting it back to _pclose --- engine/utils/command_executor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/utils/command_executor.h b/engine/utils/command_executor.h index da3196390..ee235a2f2 100644 --- a/engine/utils/command_executor.h +++ b/engine/utils/command_executor.h @@ -7,7 +7,7 @@ #ifdef _WIN32 #define POPEN _popen -#define PCLOSE windo +#define PCLOSE _pclose #else #define POPEN popen #define PCLOSE pclose From 64cf3979af56e08be27d4d3241e9c9142c61df98 Mon Sep 17 00:00:00 2001 From: Roushan Singh Date: Mon, 10 Mar 2025 09:44:51 +0530 Subject: [PATCH 4/4] chore: fix formatting --- engine/utils/command_executor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/utils/command_executor.h b/engine/utils/command_executor.h index ee235a2f2..829d62c9d 100644 --- a/engine/utils/command_executor.h +++ b/engine/utils/command_executor.h @@ -45,5 +45,5 @@ class CommandExecutor { } private: - std::unique_ptr m_pipe{nullptr, [](FILE* file) { if (file) { PCLOSE(file); } }}; + std::unique_ptr m_pipe{nullptr, [](FILE* file) { if (file) { PCLOSE(file); } }}; };