From: Tim Niemueller Date: Tue, 26 Jan 2010 23:41:05 +0000 (+0100) Subject: Main app: get rid of default plugin load exception message X-Git-Tag: 0.4~114 X-Git-Url: http://git.fawkesrobotics.org Main app: get rid of default plugin load exception message 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. --- diff --git a/src/libs/plugin/loader.cpp b/src/libs/plugin/loader.cpp index 9c94ec5..1cc8f57 100644 --- a/src/libs/plugin/loader.cpp +++ b/src/libs/plugin/loader.cpp @@ -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 * This exception is thrown if the requested plugin could not be unloaded. diff --git a/src/libs/plugin/loader.h b/src/libs/plugin/loader.h index ed869aa..42ec8a7 100644 --- a/src/libs/plugin/loader.h +++ b/src/libs/plugin/loader.h @@ -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 diff --git a/src/mainapp/main_thread.cpp b/src/mainapp/main_thread.cpp index b12e9d9..eb0c4bc 100644 --- a/src/mainapp/main_thread.cpp +++ b/src/mainapp/main_thread.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -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); } } }