Skip to content

Commit

Permalink
Implement *_plugin_get_last_exception in all plugins
Browse files Browse the repository at this point in the history
Plugins no longer discard the exception generated in
the `libdnf_plugin_new_instance` and `dnf5_plugin_new_instance`
functions. The exception is saved.

Plugins implement the `libdnf_plugin_get_last_exception` or
`dnf5_plugin_get_last_exception` function to retrieve the saved
exception.
  • Loading branch information
jrohel authored and m-blaha committed Feb 12, 2025
1 parent 7520e72 commit 706b6a6
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 2 deletions.
7 changes: 7 additions & 0 deletions dnf5-plugins/automatic_plugin/automatic_cmd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ std::vector<std::unique_ptr<Command>> AutomaticCmdPlugin::create_commands() {
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -67,9 +69,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new AutomaticCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
7 changes: 7 additions & 0 deletions dnf5-plugins/builddep_plugin/builddep_cmd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ std::vector<std::unique_ptr<Command>> BuildDepCmdPlugin::create_commands() {
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -67,9 +69,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new BuildDepCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
7 changes: 7 additions & 0 deletions dnf5-plugins/changelog_plugin/changelog_cmd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ std::vector<std::unique_ptr<Command>> ChangelogCmdPlugin::create_commands() {
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -67,9 +69,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new ChangelogCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ std::vector<std::unique_ptr<Command>> ConfigManagerCmdPlugin::create_commands()
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -67,9 +69,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new ConfigManagerCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
7 changes: 7 additions & 0 deletions dnf5-plugins/copr_plugin/copr_cmd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class CoprCmdPlugin : public IPlugin {
};


std::exception_ptr last_exception;

} // namespace


Expand All @@ -87,9 +89,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new CoprCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ std::vector<std::unique_ptr<Command>> NeedsRestartingCmdPlugin::create_commands(
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -67,9 +69,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new NeedsRestartingCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
7 changes: 7 additions & 0 deletions dnf5-plugins/repoclosure_plugin/repoclosure_cmd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ std::vector<std::unique_ptr<Command>> RepoclosureCmdPlugin::create_commands() {
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -86,9 +88,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new RepoclosureCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
7 changes: 7 additions & 0 deletions dnf5-plugins/reposync_plugin/reposync_cmd_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ std::vector<std::unique_ptr<Command>> ReposyncCmdPlugin::create_commands() {
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -86,9 +88,14 @@ PluginVersion dnf5_plugin_get_version(void) {
IPlugin * dnf5_plugin_new_instance([[maybe_unused]] ApplicationVersion application_version, Context & context) try {
return new ReposyncCmdPlugin(context);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void dnf5_plugin_delete_instance(IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * dnf5_plugin_get_last_exception(void) {
return &last_exception;
}
8 changes: 8 additions & 0 deletions libdnf5-plugins/actions/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1983,6 +1983,9 @@ void Actions::on_transaction(const libdnf5::base::Transaction & transaction, con
}
}


std::exception_ptr last_exception;

} // namespace

PluginAPIVersion libdnf_plugin_get_api_version(void) {
Expand All @@ -2003,9 +2006,14 @@ plugin::IPlugin * libdnf_plugin_new_instance(
libdnf5::ConfigParser & parser) try {
return new Actions(data, parser);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void libdnf_plugin_delete_instance(plugin::IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * libdnf_plugin_get_last_exception(void) {
return &last_exception;
}
8 changes: 8 additions & 0 deletions libdnf5-plugins/appstream/appstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ void AppstreamPlugin::install_appstream(libdnf5::repo::Repo * repo) {
}
}


std::exception_ptr last_exception;

} // namespace


Expand All @@ -121,9 +124,14 @@ plugin::IPlugin * libdnf_plugin_new_instance(
libdnf5::ConfigParser & parser) try {
return new AppstreamPlugin(data, parser);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void libdnf_plugin_delete_instance(plugin::IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * libdnf_plugin_get_last_exception(void) {
return &last_exception;
}
8 changes: 8 additions & 0 deletions libdnf5-plugins/expired-pgp-keys/expired-pgp-keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ void ExpiredPgpKeys::process_expired_pgp_keys(const libdnf5::base::Transaction &
}
}


std::exception_ptr last_exception;

} // namespace

PluginAPIVersion libdnf_plugin_get_api_version(void) {
Expand All @@ -243,9 +246,14 @@ plugin::IPlugin * libdnf_plugin_new_instance(
libdnf5::ConfigParser & parser) try {
return new ExpiredPgpKeys(data, parser);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void libdnf_plugin_delete_instance(plugin::IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * libdnf_plugin_get_last_exception(void) {
return &last_exception;
}
12 changes: 10 additions & 2 deletions libdnf5-plugins/python_plugins_loader/python_plugins_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ static void fetch_python_error_to_exception(const char * msg) {
throw std::runtime_error(msg + pycomp_str.get_string());
}

} // namespace

/// Load Python plugin from path
void PythonPluginLoader::load_plugin_file(const fs::path & file_path) {
// Very High Level Embedding
Expand Down Expand Up @@ -316,6 +314,11 @@ void PythonPluginLoader::load_plugins() {
}


std::exception_ptr last_exception;

} // namespace


PluginAPIVersion libdnf_plugin_get_api_version(void) {
return REQUIRED_PLUGIN_API_VERSION;
}
Expand All @@ -334,9 +337,14 @@ plugin::IPlugin * libdnf_plugin_new_instance(
libdnf5::ConfigParser & parser) try {
return new PythonPluginLoader(data, parser);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void libdnf_plugin_delete_instance(plugin::IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * libdnf_plugin_get_last_exception(void) {
return &last_exception;
}
8 changes: 8 additions & 0 deletions libdnf5-plugins/rhsm/rhsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ void Rhsm::setup_enrollments() {
}
}


std::exception_ptr last_exception;

} // namespace

PluginAPIVersion libdnf_plugin_get_api_version(void) {
Expand All @@ -160,9 +163,14 @@ plugin::IPlugin * libdnf_plugin_new_instance(
libdnf5::ConfigParser & parser) try {
return new Rhsm(data, parser);
} catch (...) {
last_exception = std::current_exception();
return nullptr;
}

void libdnf_plugin_delete_instance(plugin::IPlugin * plugin_object) {
delete plugin_object;
}

std::exception_ptr * libdnf_plugin_get_last_exception(void) {
return &last_exception;
}

0 comments on commit 706b6a6

Please sign in to comment.