requester: Use return code instead of throwing exception
The coroutine API should only forward error code and response data
to the caller when sends/receives PLDM message instead check the
response and thrown exception.
The `sendRecvMsg` API will response tuple of error code, response and
response length as below:
+ [error_code, _, _] if registerRequest fails with `error_code`.
+ [PLDM_ERROR_NOT_READY, nullptr, 0] if the request is timed out.
+ [PLDM_SUCCESS, resp, len] if succeeded.
Signed-off-by: Khang Nguyen Duy <khangng@amperecomputing.com>
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Change-Id: Id8262d147e9fed50af8f55f1c611a3a3b153b6e3
diff --git a/platform-mc/terminus_manager.cpp b/platform-mc/terminus_manager.cpp
index 13a933f..0b5cf88 100644
--- a/platform-mc/terminus_manager.cpp
+++ b/platform-mc/terminus_manager.cpp
@@ -363,24 +363,28 @@
const pldm_msg** responseMsg,
size_t* responseLen)
{
+ int rc = 0;
try
{
- std::tie(*responseMsg, *responseLen) =
+ std::tie(rc, *responseMsg, *responseLen) =
co_await handler.sendRecvMsg(eid, std::move(request));
- co_return PLDM_SUCCESS;
}
catch (const sdbusplus::exception_t& e)
{
lg2::error(
- "Send and Receive PLDM message over MCTP failed with error - {ERROR}.",
+ "Send and Receive PLDM message over MCTP throw error - {ERROR}.",
"ERROR", e);
co_return PLDM_ERROR;
}
- catch (const int& rc)
+ catch (const int& e)
{
- lg2::error("sendRecvPldmMsgOverMctp failed. rc={RC}", "RC", rc);
+ lg2::error(
+ "Send and Receive PLDM message over MCTP throw int error - {ERROR}.",
+ "ERROR", e);
co_return PLDM_ERROR;
}
+
+ co_return rc;
}
exec::task<int> TerminusManager::getTidOverMctp(mctp_eid_t eid, pldm_tid_t* tid)
@@ -600,11 +604,6 @@
auto rc = co_await sendRecvPldmMsgOverMctp(eid, request, responseMsg,
responseLen);
- if (responseMsg == nullptr || !responseLen)
- {
- co_return PLDM_ERROR_INVALID_DATA;
- }
-
co_return rc;
}