Main app: get rid of default plugin load exception message
authorTim Niemueller <niemueller@kbsg.rwth-aachen.de>
Tue, 26 Jan 2010 23:41:05 +0000 (00:41 +0100)
committerTim Niemueller <niemueller@kbsg.rwth-aachen.de>
Tue, 26 Jan 2010 23:41:05 +0000 (00:41 +0100)
The first experience when running Fawkes is that you get an error
with the exception that the default plugin could not be loaded.
That has bugged me for long enough now. The PluginLoadException
can now report which plugin caused the exception, and the mainapp
ignores the plugin load exception now if the plugin which caused
this exception is "default". Exceptions other than
PluginLoadException are reported as before.

src/libs/plugin/loader.cpp
src/libs/plugin/loader.h
src/mainapp/main_thread.cpp

index 9c94ec5..1cc8f57 100644 (file)
@@ -54,12 +54,17 @@ class PluginLoaderData
  * @param message message of exception
  */
 PluginLoadException::PluginLoadException(const char *plugin, const char *message)
-  : Exception()
+  : Exception(), __plugin_name(plugin)
 {
   append("Plugin '%s' could not be loaded: %s", plugin, message);
 }
 
 
+/** Destructor. */
+PluginLoadException::~PluginLoadException() throw()
+{
+}
+
 /** Constructor.
  * @param plugin name of the plugin that caused the exception
  * @param message message of exception
@@ -67,12 +72,21 @@ PluginLoadException::PluginLoadException(const char *plugin, const char *message
  */
 PluginLoadException::PluginLoadException(const char *plugin, const char *message,
                                         Exception &e)
-  : Exception()
+  : Exception(), __plugin_name(plugin)
 {
   append("Plugin '%s' could not be loaded: %s", plugin, message);
   copy_messages(e);
 }
 
+/** Get name of plugin which failed to load.
+ * @return plugin name
+ */
+std::string
+PluginLoadException::plugin_name() const
+{
+  return __plugin_name;
+}
+
 
 /** @class PluginUnloadException <plugin/loader.h>
  * This exception is thrown if the requested plugin could not be unloaded.
index ed869aa..42ec8a7 100644 (file)
@@ -43,6 +43,12 @@ class PluginLoadException : public Exception
  public:
   PluginLoadException(const char *plugin, const char *message);
   PluginLoadException(const char *plugin, const char *message, Exception &e);
+  ~PluginLoadException() throw();
+
+  std::string  plugin_name() const;
+
+ private:
+  std::string __plugin_name;
 };
 
 class PluginUnloadException : public Exception
index b12e9d9..eb0c4bc 100644 (file)
@@ -43,6 +43,7 @@
 #include <blackboard/local.h>
 #include <aspect/inifin.h>
 #include <plugin/manager.h>
+#include <plugin/loader.h>
 #include <plugin/net/handler.h>
 
 #include <cstdio>
@@ -320,10 +321,18 @@ FawkesMainThread::once()
   } else {
     try {
       __plugin_manager->load("default");
+    } catch (PluginLoadException &e) {
+      if (e.plugin_name() != "default") {
+       // only print if name is not default, i.e. one of the plugins that
+       // the default meta plugin
+       __multi_logger->log_error("FawkesMainThread", "Failed to load default "
+                                 "plugins, exception follows");
+       __multi_logger->log_error("FawkesMainThread", e);
+      }
     } catch (Exception &e) {
-      // ignored, there is no default meta plugin set
-      __multi_logger->log_error("FawkesMainThread", "Failed to load default plugins, exception follows");
-      __multi_logger->log_error("FawkesMainThread", e);
+       __multi_logger->log_error("FawkesMainThread", "Failed to load default "
+                                 "plugins, exception follows");
+       __multi_logger->log_error("FawkesMainThread", e);
     }
   }
 }