Mercurial > irccd
changeset 872:fbed78ca4a25
irccd: use plugin id in errors, closes #890
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 28 Jul 2019 16:07:30 +0200 |
parents | dbd611105f57 |
children | f50164e4f794 |
files | libirccd-daemon/irccd/daemon/plugin.cpp libirccd-daemon/irccd/daemon/plugin.hpp libirccd-daemon/irccd/daemon/plugin_service.cpp libirccd-daemon/irccd/daemon/plugin_service.hpp libirccd-daemon/irccd/daemon/transport_command.cpp libirccd-js/irccd/js/plugin.cpp |
diffstat | 6 files changed, 28 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/libirccd-daemon/irccd/daemon/plugin.cpp Fri Jul 26 21:30:00 2019 +0000 +++ b/libirccd-daemon/irccd/daemon/plugin.cpp Sun Jul 28 16:07:30 2019 +0200 @@ -209,9 +209,9 @@ return nullptr; } -plugin_error::plugin_error(error errc, std::string_view name, std::string_view message) +plugin_error::plugin_error(error errc, std::string id, std::string message) : system_error(make_error_code(errc)) - , name_(std::move(name)) + , id_(std::move(id)) , message_(std::move(message)) { std::ostringstream oss; @@ -227,9 +227,9 @@ what_ = oss.str(); } -auto plugin_error::get_name() const noexcept -> const std::string& +auto plugin_error::get_id() const noexcept -> const std::string& { - return name_; + return id_; } auto plugin_error::get_message() const noexcept -> const std::string&
--- a/libirccd-daemon/irccd/daemon/plugin.hpp Fri Jul 26 21:30:00 2019 +0000 +++ b/libirccd-daemon/irccd/daemon/plugin.hpp Sun Jul 28 16:07:30 2019 +0200 @@ -408,7 +408,7 @@ }; private: - std::string name_; + std::string id_; std::string message_; std::string what_; @@ -417,17 +417,17 @@ * Constructor. * * \param code the error code - * \param name the plugin name + * \param id the plugin id * \param message the optional message (e.g. error from plugin) */ - plugin_error(error code, std::string_view name = "", std::string_view message = ""); + plugin_error(error code, std::string id, std::string message = ""); /** - * Get the plugin name. + * Get the plugin identifier. * - * \return the name + * \return the id */ - auto get_name() const noexcept -> const std::string&; + auto get_id() const noexcept -> const std::string&; /** * Get the additional message.
--- a/libirccd-daemon/irccd/daemon/plugin_service.cpp Fri Jul 26 21:30:00 2019 +0000 +++ b/libirccd-daemon/irccd/daemon/plugin_service.cpp Sun Jul 28 16:07:30 2019 +0200 @@ -90,7 +90,7 @@ auto plugin = get(id); if (!plugin) - throw plugin_error(plugin_error::not_found, id); + throw plugin_error(plugin_error::not_found, std::string(id)); return plugin; } @@ -185,7 +185,7 @@ void plugin_service::load(std::string_view id, std::string_view path) { if (has(id)) - throw plugin_error(plugin_error::already_exists, id); + throw plugin_error(plugin_error::already_exists, std::string(id)); std::shared_ptr<plugin> plugin; @@ -195,18 +195,18 @@ else plugin = open(id, std::move(path)); } catch (...) { - throw plugin_error(plugin_error::exec_error, id); + throw plugin_error(plugin_error::exec_error, std::string(id)); } if (!plugin) - throw plugin_error(plugin_error::not_found, id); + throw plugin_error(plugin_error::not_found, std::string(id)); try { plugin->set_options(get_options(id)); plugin->set_templates(get_templates(id)); plugin->set_paths(get_paths(id)); } catch (...) { - throw plugin_error(plugin_error::exec_error, id); + throw plugin_error(plugin_error::exec_error, std::string(id)); } exec(plugin, &plugin::handle_load, bot_); @@ -219,7 +219,7 @@ auto plugin = get(id); if (!plugin) - throw plugin_error(plugin_error::not_found, id); + throw plugin_error(plugin_error::not_found, std::string(id)); exec(plugin, &plugin::handle_reload, bot_); } @@ -233,7 +233,7 @@ const auto it = std::find_if(plugins_.begin(), plugins_.end(), find); if (it == plugins_.end()) - throw plugin_error(plugin_error::not_found, id); + throw plugin_error(plugin_error::not_found, std::string(id)); // Erase first, in case of throwing. const auto save = *it;
--- a/libirccd-daemon/irccd/daemon/plugin_service.hpp Fri Jul 26 21:30:00 2019 +0000 +++ b/libirccd-daemon/irccd/daemon/plugin_service.hpp Sun Jul 28 16:07:30 2019 +0200 @@ -218,9 +218,9 @@ try { std::invoke(std::forward<Func>(fn), *plugin, std::forward<Args>(args)...); } catch (const std::exception& ex) { - throw plugin_error(plugin_error::exec_error, plugin->get_name(), ex.what()); + throw plugin_error(plugin_error::exec_error, plugin->get_id(), ex.what()); } catch (...) { - throw plugin_error(plugin_error::exec_error, plugin->get_name()); + throw plugin_error(plugin_error::exec_error, plugin->get_id()); } } @@ -237,7 +237,7 @@ auto plugin = find(name); if (!plugin) - throw plugin_error(plugin_error::not_found, plugin->get_name()); + throw plugin_error(plugin_error::not_found, plugin->get_id()); exec(std::move(plugin), std::forward<Func>(fn), std::forward<Args>(args)...); }
--- a/libirccd-daemon/irccd/daemon/transport_command.cpp Fri Jul 26 21:30:00 2019 +0000 +++ b/libirccd-daemon/irccd/daemon/transport_command.cpp Sun Jul 28 16:07:30 2019 +0200 @@ -138,7 +138,7 @@ const auto id = args.get<std::string>("plugin"); if (!id || !string_util::is_identifier(*id)) - throw plugin_error(plugin_error::invalid_identifier); + throw plugin_error(plugin_error::invalid_identifier, id.value_or("")); const auto plugin = bot.get_plugins().require(*id); @@ -162,7 +162,7 @@ const auto id = args.get<std::string>("plugin"); if (!id || !string_util::is_identifier(*id)) - throw plugin_error(plugin_error::invalid_identifier); + throw plugin_error(plugin_error::invalid_identifier, id.value_or("")); const auto plugin = bot.get_plugins().require(*id); @@ -211,7 +211,7 @@ const auto id = args.get<std::string>("plugin"); if (!id || !string_util::is_identifier(*id)) - throw plugin_error(plugin_error::invalid_identifier); + throw plugin_error(plugin_error::invalid_identifier, id.value_or("")); bot.get_plugins().load(*id, ""); client.success("plugin-load"); @@ -231,7 +231,7 @@ const auto id = args.get<std::string>("plugin"); if (!id || !string_util::is_identifier(*id)) - throw plugin_error(plugin_error::invalid_identifier); + throw plugin_error(plugin_error::invalid_identifier, id.value_or("")); bot.get_plugins().reload(*id); client.success("plugin-reload"); @@ -251,7 +251,7 @@ const auto id = args.get<std::string>("plugin"); if (!id || !string_util::is_identifier(*id)) - throw plugin_error(plugin_error::invalid_identifier); + throw plugin_error(plugin_error::invalid_identifier, id.value_or("")); bot.get_plugins().unload(*id); client.success("plugin-unload");
--- a/libirccd-js/irccd/js/plugin.cpp Fri Jul 26 21:30:00 2019 +0000 +++ b/libirccd-js/irccd/js/plugin.cpp Sun Jul 28 16:07:30 2019 +0200 @@ -131,7 +131,7 @@ push(std::forward<Args>(args)...); if (duk_pcall(context_, sizeof... (Args)) != 0) - throw plugin_error(plugin_error::exec_error, get_name(), duk::get_stack(context_, -1).get_stack()); + throw plugin_error(plugin_error::exec_error, get_id(), duk::get_stack(context_, -1).get_stack()); duk_pop(context_); } @@ -230,7 +230,7 @@ std::ifstream input(path_); if (!input) - throw plugin_error(plugin_error::exec_error, get_name(), std::strerror(errno)); + throw plugin_error(plugin_error::exec_error, get_id(), std::strerror(errno)); std::string data( std::istreambuf_iterator<char>(input.rdbuf()), @@ -238,7 +238,7 @@ ); if (duk_peval_string(context_, data.c_str())) - throw plugin_error(plugin_error::exec_error, get_name(), duk::get_stack(context_, -1).get_stack()); + throw plugin_error(plugin_error::exec_error, get_id(), duk::get_stack(context_, -1).get_stack()); } void plugin::handle_command(bot&, const message_event& event)