diff options
Diffstat (limited to 'app/watchdog_service.cpp')
-rw-r--r-- | app/watchdog_service.cpp | 58 |
1 files changed, 45 insertions, 13 deletions
diff --git a/app/watchdog_service.cpp b/app/watchdog_service.cpp index 898cf77..6c9edd4 100644 --- a/app/watchdog_service.cpp +++ b/app/watchdog_service.cpp @@ -1,10 +1,12 @@ #include "watchdog_service.hpp" +#include <exception> #include <phosphor-logging/elog.hpp> #include <phosphor-logging/elog-errors.hpp> #include <phosphor-logging/log.hpp> #include <sdbusplus/bus.hpp> #include <sdbusplus/message.hpp> +#include <stdexcept> #include <string> #include <xyz/openbmc_project/Common/error.hpp> #include <xyz/openbmc_project/State/Watchdog/server.hpp> @@ -71,17 +73,31 @@ WatchdogService::Properties WatchdogService::getProperties() log<level::ERR>("WatchdogService: Method error getting properties"); elog<InternalFailure>(); } + try + { + std::map<std::string, variant<bool, uint64_t, std::string>> properties; + response.read(properties); + Properties wd_prop; + wd_prop.initialized = get<bool>(properties.at("Initialized")); + wd_prop.enabled = get<bool>(properties.at("Enabled")); + wd_prop.expireAction = Watchdog::convertActionFromString( + get<std::string>(properties.at("ExpireAction"))); + wd_prop.interval = get<uint64_t>(properties.at("Interval")); + wd_prop.timeRemaining = get<uint64_t>(properties.at("TimeRemaining")); + return wd_prop; + } + catch (const std::exception& e) + { + log<level::ERR>("WatchdogService: Decode error in get properties", + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", response.get_signature())); + elog<InternalFailure>(); + } - std::map<std::string, variant<bool, uint64_t, std::string>> properties; - response.read(properties); - Properties wd_prop; - wd_prop.initialized = get<bool>(properties.at("Initialized")); - wd_prop.enabled = get<bool>(properties.at("Enabled")); - wd_prop.expireAction = Watchdog::convertActionFromString( - get<std::string>(properties.at("ExpireAction"))); - wd_prop.interval = get<uint64_t>(properties.at("Interval")); - wd_prop.timeRemaining = get<uint64_t>(properties.at("TimeRemaining")); - return wd_prop; + // Needed instead of elog<InternalFailure>() since the compiler can't + // deduce the that elog<>() always throws + throw std::runtime_error( + "WatchdogService: Should not reach end of getProperties"); } template <typename T> @@ -103,9 +119,25 @@ T WatchdogService::getProperty(const std::string& key) entry("PROPERTY=%s", key.c_str())); elog<InternalFailure>(); } - variant<T> value; - response.read(value); - return get<T>(value); + try + { + variant<T> value; + response.read(value); + return get<T>(value); + } + catch (const std::exception& e) + { + log<level::ERR>("WatchdogService: Decode error in get property", + entry("PROPERTY=%s", key.c_str()), + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", response.get_signature())); + elog<InternalFailure>(); + } + + // Needed instead of elog<InternalFailure>() since the compiler can't + // deduce the that elog<>() always throws + throw std::runtime_error( + "WatchdogService: Should not reach end of getProperty"); } template <typename T> |