# HG changeset patch # User David Demelier # Date 1564322850 -7200 # Node ID fbed78ca4a2533993d83aa19517591dfdc2fcf1e # Parent dbd611105f577446fd99990d40a6efeaafa10358 irccd: use plugin id in errors, closes #890 diff -r dbd611105f57 -r fbed78ca4a25 libirccd-daemon/irccd/daemon/plugin.cpp --- 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& diff -r dbd611105f57 -r fbed78ca4a25 libirccd-daemon/irccd/daemon/plugin.hpp --- 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. diff -r dbd611105f57 -r fbed78ca4a25 libirccd-daemon/irccd/daemon/plugin_service.cpp --- 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; @@ -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; diff -r dbd611105f57 -r fbed78ca4a25 libirccd-daemon/irccd/daemon/plugin_service.hpp --- 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(fn), *plugin, std::forward(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(fn), std::forward(args)...); } diff -r dbd611105f57 -r fbed78ca4a25 libirccd-daemon/irccd/daemon/transport_command.cpp --- 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("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("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("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("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("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"); diff -r dbd611105f57 -r fbed78ca4a25 libirccd-js/irccd/js/plugin.cpp --- 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)...); 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(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)