Do not terminate settingsd on plugin exception. 09/13809/1
authorOssama Othman <ossama.othman@intel.com>
Mon, 16 Dec 2013 20:49:42 +0000 (12:49 -0800)
committerOssama Othman <ossama.othman@intel.com>
Mon, 16 Dec 2013 20:49:42 +0000 (12:49 -0800)
Improve exception reporting, as well.

Change-Id: I6e4c839caca4a08c71e15335d2997403f39aa21b
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
lib/loader.cpp
lib/manager.cpp
src/websocket_server.cpp

index b017879..3df7eb2 100644 (file)
@@ -31,7 +31,7 @@
 #include <settingsd/registrar.hpp>
 #include <settingsd/event_callback.hpp>
 
-#include <stdexcept>
+#include <system_error>
 #include <dlfcn.h>
 
 
@@ -49,7 +49,7 @@ ivi::settings::loader::loader(std::string const & plugin_name,
   : handle_(dlopen(plugin_name.c_str(), RTLD_LAZY | RTLD_GLOBAL))
 {
   if (handle_ == nullptr) {
-    throw std::logic_error(dlerror());
+    throw std::system_error(std::error_code(), dlerror());
   }
 
   // Reset any lingering dynamic linking related errors (see
@@ -64,7 +64,7 @@ ivi::settings::loader::loader(std::string const & plugin_name,
             "register_settings"));
 
   if (register_settings == nullptr)
-    throw std::logic_error(dlerror());
+    throw std::system_error(std::error_code(), dlerror());
 
   // Now create the underlying settings implementation.
 
index 3f8ad7c..1766d94 100644 (file)
@@ -69,8 +69,8 @@ void
 ivi::settings::manager::load_settings(std::string const & dir)
 {
   if (dir.length() == 0)
-    throw std::runtime_error("Zero length settings plugin "
-                             "directory path.");
+    throw std::invalid_argument("Zero length settings plugin "
+                                "directory path.");
 
   namespace fs = boost::filesystem;
 
@@ -103,7 +103,7 @@ ivi::settings::manager::load_settings(std::string const & dir)
 
         loaders_.push_back(std::move(plugin));
       }
-      catch (std::logic_error & e) {
+      catch (std::exception & e) {
         /**
          * @todo I really hate catching an exception like this, but I
          *       really don't want to resort to a construct/init()
@@ -111,19 +111,22 @@ ivi::settings::manager::load_settings(std::string const & dir)
          */
         std::cerr << "Error loading plugin: " << e.what() << "\n";
       }
+      catch (...) {
+        std::cerr << "Ignoring unknown exception thrown from plugin.\n";
+      }
     }
 
     if (settings_.size() == 0) {
-      throw std::runtime_error("Settings plugin directory \""
-                               + dir + "\" has no plugins.");
+      throw std::invalid_argument("Settings plugin directory \""
+                                  + dir + "\" has no plugins.");
     } else {
-      std::cerr << "Registered settings plugins: \n";
+      std::cerr << "Registered settings plugins:\n";
       for (auto const & i : settings_)
         std::cerr << "\t" << i.first << '\n';
     }
   } else {
-    throw std::runtime_error("Settings plugin directory \""
-                             + dir + "\" does not exist.");
+    throw std::invalid_argument("Settings plugin directory \""
+                                + dir + "\" does not exist.");
   }
 }
 
@@ -140,7 +143,8 @@ ivi::settings::manager::dispatch(std::string request,
   unique_ptr<JsonParser> const parser(json_parser_new());
   json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr);
 
-  JsonReader * const reader = json_reader_new(json_parser_get_root(parser.get()));
+  JsonReader * const reader =
+    json_reader_new(json_parser_get_root(parser.get()));
   unique_ptr<JsonReader> const safe_reader(reader);
 
   // Retrieve setting name and transcation ID from the JSON request
index 636e893..5f158af 100644 (file)
@@ -29,7 +29,7 @@
 #include "../lib/config.hpp"
 #include "../lib/manager.hpp"
 
-#include <stdexcept>
+#include <system_error>
 
 
 
@@ -136,7 +136,9 @@ ivi::settings::websocket_server::websocket_server(
 
   context_ = libwebsocket_create_context(&info);
   if (context_ == nullptr)
-    throw std::runtime_error("Unable to initialize websocket.");
+    throw std::system_error(errno,
+                            std::system_category(),
+                            "Unable to initialize websocket.");
 
   std::cout << "\n" PACKAGE_NAME " listening for requests on port "
             << info.port << ".\n";