ipmi: catch SdBusErrors on bus call failures
Now sdbusplus call and call_noreply can throw an SdBusError exception.
This code changes from checking .is_method_error() to catching the
exception.
Issue: 4
Change-Id: I07bbe5dbbd91d72ca75eeb14861d56aae5f3afed
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/ipmi/manualcmds.cpp b/ipmi/manualcmds.cpp
index eabcd0a..798deab 100644
--- a/ipmi/manualcmds.cpp
+++ b/ipmi/manualcmds.cpp
@@ -84,22 +84,20 @@
propertiesintf, "GetAll");
pimMsg.append(intf);
- auto valueResponseMsg = propertyReadBus.call(pimMsg);
- if (valueResponseMsg.is_method_error())
+ try
+ {
+ auto valueResponseMsg = propertyReadBus.call(pimMsg);
+
+ PropertyMap propMap;
+ valueResponseMsg.read(propMap);
+
+ *value = sdbusplus::message::variant_ns::get<bool>(propMap[property]);
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
{
return IPMI_CC_INVALID;
}
- PropertyMap propMap;
- valueResponseMsg.read(propMap);
-
- if (propMap.size() != 2)
- {
- return IPMI_CC_INVALID;
- }
-
- *value = sdbusplus::message::variant_ns::get<bool>(propMap[property]);
-
return IPMI_CC_OK;
}
@@ -193,8 +191,12 @@
pimMsg.append(intf);
pimMsg.append(manualProperty);
pimMsg.append(v);
- auto responseMsg = PropertyWriteBus.call(pimMsg);
- if (responseMsg.is_method_error())
+
+ try
+ {
+ PropertyWriteBus.call_noreply(pimMsg);
+ }
+ catch (const sdbusplus::exception::SdBusError& ex)
{
rc = IPMI_CC_INVALID;
}