diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2018-07-17 10:51:36 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2018-07-17 10:51:36 -0500 |
commit | 86be476bfb6acfd413afff449a357123639eb29e (patch) | |
tree | 4f4f2f24500a4e54e01bdec5b6a392eb59ffdda7 | |
parent | b0de1d6a88cee65cfc1041d26e04ac443ca1af4a (diff) | |
download | phosphor-fan-presence-86be476bfb6acfd413afff449a357123639eb29e.tar.gz phosphor-fan-presence-86be476bfb6acfd413afff449a357123639eb29e.zip |
Handle SdBusError exceptions
When the SdBusError exception was added, all sdbusplus::bus::call
function use required this exception be handled appropriately in each
case where it could occur. These changes are the result of handling the
possibility of this exception correctly within the fan applications.
Change-Id: I6ecef3008412b299a4fedbb13716f656cfbf1a90
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
-rw-r--r-- | control/fan.cpp | 26 | ||||
-rw-r--r-- | control/functor.hpp | 7 | ||||
-rw-r--r-- | sdbusplus.hpp | 15 |
3 files changed, 35 insertions, 13 deletions
diff --git a/control/fan.cpp b/control/fan.cpp index d4303cf..c86186f 100644 --- a/control/fan.cpp +++ b/control/fan.cpp @@ -65,13 +65,25 @@ void Fan::setSpeed(uint64_t speed) for (auto& sensor : _sensors) { auto value = speed; - util::SDBusPlus::setProperty<uint64_t>( - _bus, - sensor.second, - sensor.first, - _interface, - FAN_TARGET_PROPERTY, - std::move(value)); + try + { + util::SDBusPlus::setProperty<uint64_t>( + _bus, + sensor.second, + sensor.first, + _interface, + FAN_TARGET_PROPERTY, + std::move(value)); + } + catch (const sdbusplus::exception::SdBusError&) + { + throw util::DBusPropertyError{ + "DBus set property failed", + sensor.second, + sensor.first, + _interface, + FAN_TARGET_PROPERTY}; + } } _targetSpeed = speed; diff --git a/control/functor.hpp b/control/functor.hpp index 17ae3af..e86bae7 100644 --- a/control/functor.hpp +++ b/control/functor.hpp @@ -113,7 +113,12 @@ struct PropertyChanged _property); _handler(zone, std::forward<T>(val)); } - catch (const util::DBusError& e) + catch (const sdbusplus::exception::SdBusError&) + { + // Property will not be used unless a property changed + // signal message is received for this property. + } + catch (const util::DBusError&) { // Property will not be used unless a property changed // signal message is received for this property. diff --git a/sdbusplus.hpp b/sdbusplus.hpp index 3a6cd65..41c7fe2 100644 --- a/sdbusplus.hpp +++ b/sdbusplus.hpp @@ -149,14 +149,19 @@ class SDBusPlus interface.c_str(), method.c_str()); reqMsg.append(std::forward<Args>(args)...); - auto respMsg = bus.call(reqMsg); - - if (respMsg.is_method_error()) + try + { + auto respMsg = bus.call(reqMsg); + if (respMsg.is_method_error()) + { + throw DBusMethodError{busName, path, interface, method}; + } + return respMsg; + } + catch (const sdbusplus::exception::SdBusError&) { throw DBusMethodError{busName, path, interface, method}; } - - return respMsg; } /** @brief Invoke a method. */ |