Trace mapper and inventory errors

Add journal error entries for error conditions on mapper and inventory
manager update calls.

Change-Id: Iecb310575414878f4b83c24136e6ae1312c6f7aa
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index e6df71c..610e543 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,8 +10,10 @@
 nodist_phosphor_fan_presence_tach_SOURCES = \
 	fan_detect_defs.cpp
 
-phosphor_fan_presence_tach_LDFLAGS = $(SDBUSPLUS_LIBS)
-phosphor_fan_presence_tach_CXXFLAGS = $(SDBUSPLUS_CFLAGS)
+phosphor_fan_presence_tach_LDFLAGS = $(SDBUSPLUS_LIBS) $(PHOSPHOR_LOGGING_LIBS)
+phosphor_fan_presence_tach_CXXFLAGS = \
+	$(SDBUSPLUS_CFLAGS) \
+	$(PHOSPHOR_LOGGING_CFLAGS)
 
 BUILT_SOURCES = fan_detect_defs.cpp
 CLEANFILES = fan_detect_defs.cpp
diff --git a/configure.ac b/configure.ac
index 648d018..d5659f3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,8 @@
 # Checks for libraries.
 PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus], ,
 [AC_MSG_ERROR([The openbmc/sdbusplus package is required])])
+PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging], ,
+[AC_MSG_ERROR([The openbmc/phosphor-logging package is required])])
 
 # Checks for header files.
 
diff --git a/fan_enclosure.cpp b/fan_enclosure.cpp
index b2ea9f7..998bd50 100644
--- a/fan_enclosure.cpp
+++ b/fan_enclosure.cpp
@@ -1,4 +1,5 @@
 #include <algorithm>
+#include <phosphor-logging/log.hpp>
 #include "fan_enclosure.hpp"
 
 
@@ -9,6 +10,8 @@
 namespace presence
 {
 
+using namespace phosphor::logging;
+
 //TODO Should get these from phosphor-objmgr config.h
 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/ObjectMapper";
@@ -50,7 +53,8 @@
     auto mapperResponseMsg = bus.call(mapperCall);
     if (mapperResponseMsg.is_method_error())
     {
-        //TODO Retry or throw exception/log error?
+        throw std::runtime_error(
+            "Error in mapper call to get inventory service name");
     }
 
     std::map<std::string, std::vector<std::string>> mapperResponse;
@@ -58,7 +62,8 @@
 
     if (mapperResponse.empty())
     {
-        //TODO Nothing found, throw exception/log error?
+        throw std::runtime_error(
+            "Error in mapper response for inventory service name");
     }
 
     return mapperResponse.begin()->first;
@@ -69,7 +74,16 @@
     //Get inventory object for this fan
     ObjectMap invObj = getObjectMap();
     //Get inventory manager service name from mapper
-    std::string invService = getInvService();
+    std::string invService;
+    try
+    {
+        invService = getInvService();
+    }
+    catch (const std::runtime_error& err)
+    {
+        log<level::ERR>(err.what());
+        return;
+    }
     // Update inventory for this fan
     auto invMsg = bus.new_method_call(invService.c_str(),
                                       INVENTORY_PATH,
@@ -79,7 +93,9 @@
     auto invMgrResponseMsg = bus.call(invMsg);
     if (invMgrResponseMsg.is_method_error())
     {
-        //TODO Handle error in notify call
+        log<level::ERR>(
+            "Error in inventory manager call to update inventory");
+        return;
     }
 }