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 <wak@google.com>
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 @@
         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 @@
                         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>