From: Michael Tremer Date: Wed, 13 Jan 2021 11:37:17 +0000 (+0000) Subject: Throw a clean exception when Pakfire was initialised with an invalid architecture X-Git-Tag: 0.9.28~1285^2~885 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03b9652a72a4e7e357c11bd70436c4c7517a3e48;p=pakfire.git Throw a clean exception when Pakfire was initialised with an invalid architecture Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index f2f4990f5..6c107a757 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -19,6 +19,7 @@ #############################################################################*/ #include +#include #include #include @@ -52,12 +53,23 @@ static int Pakfire_init(PakfireObject* self, PyObject* args, PyObject* kwds) { return -1; // Create a new Pakfire instance - self->pakfire = pakfire_create(path, arch); + self->pakfire = pakfire_create(path, arch); + if (!self->pakfire) { + switch (errno) { + // Invalid architecture + case -EINVAL: + PyErr_SetString(PyExc_ValueError, "Invalid architecture"); + break; + + // Anything else + default: + PyErr_SetNone(PyExc_OSError); + } - if (self->pakfire) - return 0; - else return -1; + } + + return 0; } static void Pakfire_dealloc(PakfireObject* self) { diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 07ff444d3..4dfbdcfd7 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -87,8 +87,10 @@ PAKFIRE_EXPORT Pakfire pakfire_create(const char* path, const char* arch) { arch = pakfire_arch_native(); // Check if the architecture is supported - if (!pakfire_arch_supported(arch)) + if (!pakfire_arch_supported(arch)) { + errno = -EINVAL; return NULL; + } Pakfire pakfire = pakfire_calloc(1, sizeof(*pakfire)); if (pakfire) {