Fix to return sane error code

Any unhandled exception in the IPMI command handler
crashes the ipmi stack. IPMI command handler also becomes
bulky to catch all exceptions which must return unspecified
errors. This fix adds a catch in the ipmi router command handler
functions, and returns IPMI_CC_UNSPECIFIED_ERROR for all the
unhandled exceptions. With this fix, exceptions which has to
throw IPMI_CC_UNSPECIFIED_ERROR, doesn't needs to be handled in the
command handlers.

Change-Id: Icf8741925d857170b2f748906edbaf6cf1e55cdc
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
diff --git a/command_table.cpp b/command_table.cpp
index 7775022..5744978 100644
--- a/command_table.cpp
+++ b/command_table.cpp
@@ -91,12 +91,22 @@
 {
     std::vector<uint8_t> response(message::parser::MAX_PAYLOAD_SIZE - 1);
     size_t respSize = commandData.size();
-
-    ipmi_ret_t ipmiRC = functor(0, 0,
-                                reinterpret_cast<void*>(commandData.data()),
-                                reinterpret_cast<void*>(response.data() + 1),
-                                &respSize, NULL);
-
+    ipmi_ret_t ipmiRC = IPMI_CC_UNSPECIFIED_ERROR;
+    try
+    {
+        ipmiRC = functor(0, 0, reinterpret_cast<void*>(commandData.data()),
+                         reinterpret_cast<void*>(response.data() + 1),
+                         &respSize, NULL);
+    }
+    // IPMI command handlers can throw unhandled exceptions, catch those
+    // and return sane error code.
+    catch (const std::exception& e)
+    {
+        std::cerr << "E> Unspecified error for command 0x" << std::hex
+                  << command.command << " - " << e.what() << "\n";
+        respSize = 0;
+        // fall through
+    }
     /*
      * respSize gets you the size of the response data for the IPMI command. The
      * first byte in a response to the IPMI command is the Completion Code.