From: Michael Tremer Date: Wed, 22 May 2024 18:12:04 +0000 (+0000) Subject: lua: Fix raising an exception if no network was found X-Git-Tag: 0.9.18~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44d35e091a3a8687840c0c6b0b1a0b667f9b6b05;p=location%2Flibloc.git lua: Fix raising an exception if no network was found Signed-off-by: Michael Tremer --- diff --git a/src/lua/database.c b/src/lua/database.c index 8328196..dfdb705 100644 --- a/src/lua/database.c +++ b/src/lua/database.c @@ -189,23 +189,18 @@ static int Database_lookup(lua_State* L) { // Perform lookup r = loc_database_lookup_from_string(self->db, address, &network); - if (r) { - switch (errno) { - // Return nil if the network was not found - case ENOENT: - lua_pushnil(L); - return 1; - - default: - return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno)); - } + if (r) + return luaL_error(L, "Could not lookup address %s: %s\n", address, strerror(errno)); + + // Nothing found + if (!network) { + lua_pushnil(L); + return 1; } // Create a network object - if (network) { - r = create_network(L, network); - loc_network_unref(network); - } + r = create_network(L, network); + loc_network_unref(network); return r; }