Replace error strings with logging errors in device operations

Change-Id: I0fc1c23e51a0233c18775ee712132dba7e4c7d7e
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/targeting.cpp b/targeting.cpp
index 1237025..ce3fc67 100644
--- a/targeting.cpp
+++ b/targeting.cpp
@@ -18,8 +18,11 @@
 #include <experimental/filesystem>
 #include <phosphor-logging/log.hpp>
 #include <regex>
+#include <phosphor-logging/elog.hpp>
+#include "elog-errors.hpp"
 #include "targeting.hpp"
 
+
 namespace openpower
 {
 namespace targeting
@@ -91,27 +94,35 @@
 
     //Always create P0, the FSI master.
     targets.push_back(std::make_unique<Target>(0, fsiMasterPath, swapper));
-
-    //Find the the remaining P9s dynamically based on which files show up
-    for (auto& file : fs::directory_iterator(fsiSlaveBasePath))
+    try
     {
-        std::smatch match;
-        std::string path = file.path();
-        if (std::regex_search(path, match, exp))
+        //Find the the remaining P9s dynamically based on which files show up
+        for (auto& file : fs::directory_iterator(fsiSlaveBasePath))
         {
-            auto pos = atoi(match[1].str().c_str());
-            if (pos == 0)
+            std::smatch match;
+            std::string path = file.path();
+            if (std::regex_search(path, match, exp))
             {
-                log<level::ERR>("Unexpected FSI slave device name found",
-                                entry("DEVICE_NAME=%s", path.c_str()));
-                continue;
+                auto pos = atoi(match[1].str().c_str());
+                if (pos == 0)
+                {
+                    log<level::ERR>("Unexpected FSI slave device name found",
+                                    entry("DEVICE_NAME=%s", path.c_str()));
+                    continue;
+                }
+
+                path += "/raw";
+
+                targets.push_back(std::make_unique<Target>(pos, path, swapper));
             }
-
-            path += "/raw";
-
-            targets.push_back(std::make_unique<Target>(pos, path, swapper));
         }
     }
+    catch (fs::filesystem_error& e)
+    {
+        elog<org::open_power::Proc::CFAM::OpenFailure>(
+            org::open_power::Proc::CFAM::OpenFailure::ERRNO(e.code().value()),
+            org::open_power::Proc::CFAM::OpenFailure::PATH(e.path1().c_str()));
+    }
 
     auto sortTargets = [](const std::unique_ptr<Target>& left,
                           const std::unique_ptr<Target>& right)