From a27e1f3d69b8567e9cb261f0acf8d31ac35534ae Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 22 Aug 2022 17:07:41 +0000 Subject: [PATCH] python: Fix errors for Database.lookup() Signed-off-by: Michael Tremer --- src/python/database.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/python/database.c b/src/python/database.c index de45044..250750d 100644 --- a/src/python/database.c +++ b/src/python/database.c @@ -199,18 +199,21 @@ static PyObject* Database_lookup(DatabaseObject* self, PyObject* args) { loc_network_unref(network); return obj; + } // Nothing found - } else if (r == 1) { + if (!errno) Py_RETURN_NONE; - // Invalid input - } else if (r == -EINVAL) { - PyErr_Format(PyExc_ValueError, "Invalid IP address: %s", address); - return NULL; + // Handle any errors + switch (errno) { + case EINVAL: + PyErr_Format(PyExc_ValueError, "Invalid IP address: %s", address); + + default: + PyErr_SetFromErrno(PyExc_OSError); } - // Unexpected error return NULL; } -- 2.39.5