From 1469f8adc101962c1235f9477e9d53b5ba44e72b Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 15 May 2018 14:40:59 -0700 Subject: app/watchdog_service: More useful error output This patch adds error handling around the decoding of requests to the watchdog service, to give more useful context in the case of errors. Change-Id: If668b17e88dc65a938b69d8c2cdd760456170962 Signed-off-by: William A. Kennington III --- app/watchdog_service.cpp | 58 +++++++++++++++++++++++++++++++++++++----------- 1 file 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 #include #include #include #include #include +#include #include #include #include @@ -71,17 +73,31 @@ WatchdogService::Properties WatchdogService::getProperties() log("WatchdogService: Method error getting properties"); elog(); } + try + { + std::map> properties; + response.read(properties); + Properties wd_prop; + wd_prop.initialized = get(properties.at("Initialized")); + wd_prop.enabled = get(properties.at("Enabled")); + wd_prop.expireAction = Watchdog::convertActionFromString( + get(properties.at("ExpireAction"))); + wd_prop.interval = get(properties.at("Interval")); + wd_prop.timeRemaining = get(properties.at("TimeRemaining")); + return wd_prop; + } + catch (const std::exception& e) + { + log("WatchdogService: Decode error in get properties", + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", response.get_signature())); + elog(); + } - std::map> properties; - response.read(properties); - Properties wd_prop; - wd_prop.initialized = get(properties.at("Initialized")); - wd_prop.enabled = get(properties.at("Enabled")); - wd_prop.expireAction = Watchdog::convertActionFromString( - get(properties.at("ExpireAction"))); - wd_prop.interval = get(properties.at("Interval")); - wd_prop.timeRemaining = get(properties.at("TimeRemaining")); - return wd_prop; + // Needed instead of elog() since the compiler can't + // deduce the that elog<>() always throws + throw std::runtime_error( + "WatchdogService: Should not reach end of getProperties"); } template @@ -103,9 +119,25 @@ T WatchdogService::getProperty(const std::string& key) entry("PROPERTY=%s", key.c_str())); elog(); } - variant value; - response.read(value); - return get(value); + try + { + variant value; + response.read(value); + return get(value); + } + catch (const std::exception& e) + { + log("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(); + } + + // Needed instead of elog() since the compiler can't + // deduce the that elog<>() always throws + throw std::runtime_error( + "WatchdogService: Should not reach end of getProperty"); } template -- cgit v1.2.1