Skip to content

Commit

Permalink
feat(AgentInfoPersistance): handles the exception in case a BeginTran…
Browse files Browse the repository at this point in the history
…saction/RollBack fails in the SetGroups method
  • Loading branch information
Nicogp committed Feb 5, 2025
1 parent c48c636 commit fe80020
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/agent/agent_info/src/agent_info_persistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,18 @@ bool AgentInfoPersistance::SetUUID(const std::string& uuid)

bool AgentInfoPersistance::SetGroups(const std::vector<std::string>& groupList)
{
auto transaction = m_db->BeginTransaction();
TransactionId transaction = 0;

// Handle the exception separately since it would not be necessary to perform RollBack.
try
{
transaction = m_db->BeginTransaction();
}
catch (const std::exception& e)
{
LogError("Failed to begin transaction: {}.", e.what());
return false;
}

try
{
Expand All @@ -245,7 +256,16 @@ bool AgentInfoPersistance::SetGroups(const std::vector<std::string>& groupList)
catch (const std::exception& e)
{
LogError("Error inserting group: {}.", e.what());
m_db->RollbackTransaction(transaction);

try
{
m_db->RollbackTransaction(transaction);
}
catch (const std::exception& ee)
{
LogError("Rollback failed: {}.", ee.what());
}

return false;
}
return true;
Expand Down

0 comments on commit fe80020

Please sign in to comment.