pldm: use std::expected for instance ID allocation

Refactor InstanceIdDb::next() to return
std::expected<uint8_t, InstanceIdError> instead of throwing exceptions.
This change enables callers to explicitly handle allocation errors via
value inspection, rather than relying on exception handling.

This approach prevents core dumps from uncaught exceptions and
eliminates the need for pervasive try-catch blocks.
Callers can now access the error code and message directly, improving
clarity and control of error propagation.

Note:
Errors from InstanceIdDb::next() are currently handled via early
return, which may silently discard failures.
This is a temporary solution; APIs and callers will need to be updated
in the future to propagate and handle errors explicitly.

Change-Id: Ibf2e0034b0ee725cb59adfd93b74e48db8c42cba
Signed-off-by: Eric Yang <eric.yang.wiwynn@gmail.com>
diff --git a/fw-update/device_updater.cpp b/fw-update/device_updater.cpp
index f61428b..759bf0d 100644
--- a/fw-update/device_updater.cpp
+++ b/fw-update/device_updater.cpp
@@ -19,7 +19,13 @@
 
 void DeviceUpdater::startFwUpdateFlow()
 {
-    auto instanceId = updateManager->instanceIdDb.next(eid);
+    auto instanceIdResult =
+        pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
+    if (!instanceIdResult)
+    {
+        return;
+    }
+    auto instanceId = instanceIdResult.value();
     // NumberOfComponents
     const auto& applicableComponents =
         std::get<ApplicableComponents>(fwDeviceIDRecord);
@@ -114,7 +120,13 @@
 {
     pldmRequest.reset();
 
-    auto instanceId = updateManager->instanceIdDb.next(eid);
+    auto instanceIdResult =
+        pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
+    if (!instanceIdResult)
+    {
+        return;
+    }
+    auto instanceId = instanceIdResult.value();
     // TransferFlag
     const auto& applicableComponents =
         std::get<ApplicableComponents>(fwDeviceIDRecord);
@@ -265,7 +277,13 @@
 {
     pldmRequest.reset();
 
-    auto instanceId = updateManager->instanceIdDb.next(eid);
+    auto instanceIdResult =
+        pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
+    if (!instanceIdResult)
+    {
+        return;
+    }
+    auto instanceId = instanceIdResult.value();
     const auto& applicableComponents =
         std::get<ApplicableComponents>(fwDeviceIDRecord);
     const auto& comp = compImageInfos[applicableComponents[offset]];
@@ -710,7 +728,14 @@
 void DeviceUpdater::sendActivateFirmwareRequest()
 {
     pldmRequest.reset();
-    auto instanceId = updateManager->instanceIdDb.next(eid);
+
+    auto instanceIdResult =
+        pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
+    if (!instanceIdResult)
+    {
+        return;
+    }
+    auto instanceId = instanceIdResult.value();
     Request request(
         sizeof(pldm_msg_hdr) + sizeof(struct pldm_activate_firmware_req));
     auto requestMsg = new (request.data()) pldm_msg;
@@ -781,7 +806,14 @@
 void DeviceUpdater::sendCancelUpdateComponentRequest()
 {
     pldmRequest.reset();
-    auto instanceId = updateManager->instanceIdDb.next(eid);
+
+    auto instanceIdResult =
+        pldm::utils::getInstanceId(updateManager->instanceIdDb.next(eid));
+    if (!instanceIdResult)
+    {
+        return;
+    }
+    auto instanceId = instanceIdResult.value();
     Request request(sizeof(pldm_msg_hdr));
     auto requestMsg = new (request.data()) pldm_msg;